1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

game_save() ... another stupid question

Discussion in 'Programming' started by Niall Edwards, Nov 10, 2019.

  1. Niall Edwards

    Niall Edwards Member

    Joined:
    Nov 7, 2019
    Posts:
    23
    I can see there have been quite a few questions on what this basic function does and does not save out.

    I can see that it does not save out Data Structures or Surfaces.

    However, I think it DOES save out, as far as I can seen, ALL system and user-created variables in Object instances, among other things.

    My question is - if I use event_perform_object(myChildObject, ev_Create, 0 ); to pull in variables to myChildObject instance from some other Object, with those pulled in variables (and their values which can change at runtime) be saved out by game_save() too? ***

    *** Yes, I am aware of data structures and have a heaped complex ds_map to ds_map to ds_list to ds_map structure I've built and saved too - I am just looking at perhaps simpler ways of save/loading in the meantime in development (ie. being lazy, for now...) ;)
     
    Last edited: Nov 10, 2019
  2. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,712
    All instance variables will be saved. How or by what they were created doesn't matter.
     
    Niall Edwards likes this.
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,033
    Just wanted to clarify, event_perform_object() will "pull in variables" FROM myChildObject to whatever instance is calling that function. Specifically, all the function does is load the specified object's code associated with that event and run it from the scope of the instance calling the code, regardless of whether or not an instance of the referenced object even exists in the room. It's the same thing as script_execute()... if scripts were explicitly linked to objects. Consequently, any variables created in that code will belong to the instance calling the code, not the myChildObject. This also means if an instance of myCjildObject was placed in the room and given a creation code and if myChildObject's Create event required that pre-set variable in order to run, the the instance calling event_perform_object() will cause an unknown variable error.
     
    Niall Edwards likes this.
  4. Niall Edwards

    Niall Edwards Member

    Joined:
    Nov 7, 2019
    Posts:
    23
    @TsukaYuriko - excellent, thanks. @TheouAegis , yes thanks and understood. Essentially, the childObject is the instance that is grabbing some variables to be used in it from another Object. I like the way that the event_perform_object adds in the variables created in a different object thus neatly sidestepping the single inheritance parent-to-child limitation.

    I also appreciate, I think (thanks to @IndianaBones ), that I could pull in variables to an instance (ID) simply by executing a script containing the below from the instance:-

    Code:
    with ( instance )
    {
       newVariable = "Hey, I'm a new string variable";
    }
    And then whatever the then runtime value of the newVariable was would, presumably, be saved with game_save() too...

    Excellent !

    Thanks again both.
     
    Last edited: Nov 10, 2019
  5. Niall Edwards

    Niall Edwards Member

    Joined:
    Nov 7, 2019
    Posts:
    23
    @TsukaYuriko , sorry, me again - will the standard game_save() save out 1D and 2D variables in instances too?
     
  6. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,712
    Arrays are saved.
     
    Niall Edwards likes this.
  7. Niall Edwards

    Niall Edwards Member

    Joined:
    Nov 7, 2019
    Posts:
    23
    excellent - thanks yet again...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice