Forum rules - please read before posting.

Custom Remember scripts

edited April 2014 in Technical Q&A
If I want to write a custom Remember script, do I need to modify LevelStorage.cs?

I want to save some custom data, but I really don't want to make edits to Adventure Creator source files.

Comments

  • I'm afraid you do, if it's per-scene data.  What kind of data are you trying to save?
  • Hi Chris, thanks for replying! It's global data. It's just a string that represents some state data in a singleton. Is there a better way to save global data?
  • What might be easier is to run some custom code pre save and post load. In case of the former, store whatever state info you have in AC variables, which get saved afair and for the latter fill your singelton variables with the appropriate values from AC. On the other hand, it'd probably be useful if you could directly interface with AC variables from your singleton. Is that an option for you?
  • edited April 2014
    Global data is stored in the MainData class within the SaveData script - LevelStorage is for per-scene data, which is loaded on scene changes as well as when restoring saved games.

    As domx suggests, you'd be better off storing your string into a Global Variable, as this will be saved/loaded automatically.  If you can't do this by Actions, you can do it through script.

    Each Variable has an ID number (shown to the left of it's name in the Variables Manager).  To get the string value of ID=2:

    string value = GameObject.FindWithTag (Tags.persistentEngine).GetComponent <RuntimeVariables>().GetVarValue (2);

    and to set the value:

    GameObject.FindWithTag (Tags.persistentEngine).GetComponent <RuntimeVariables>().SetValue (2, "Hello");
  • Sounds like a plan. Thanks!
  • Hopefully one last question. :-)

    In the demo scene, PlayerMenu calls SaveSystem.SaveGame(_slot) to save the game. Without modifying PlayerMenu.cs, is there a way to tell my singleton to record its state into an AC global variable first?

    Likewise, after PlayerMenu calls SaveSystem.LoadGame(_slot), is there a way to tell my singleton to retrieve its state from the global variable?

    This was the reason for my original question. Although kludgy, I thought I might be able to add a custom Remember script that would tell the singleton to do this, without having to edit any original AC files (which isn't the case).

    Unless I'm missing something that's already there, some event callbacks or SendMessage()'s would be really nice in a future update.
  • Sorry, need a bit of help understanding this: the variables are saved/loaded back in automatically.  Are you not able to just read off the value of the variable as and when you need it, or do you need to access it specifically when a game is loaded?
  • Specifically when a game is loaded. The singleton needs to process the data and push it out to other components.

    Similarly, when saving, the singleton needs to pull data from other components to generate the string.
  • You can use the MenuSystem.cs script to pull the data needed before saving, by having it happen when the Save menu is turned on:

    public static void OnMenuEnable (Menu _menu)
    {
      if (_menu.title == "Save")
      {
        // Gather data
      }
    }


    As for loading, I'm afraid that'll have to be more of a hack for now.  Insert your call at the end of the OnLevelWasLoaded function in SaveSystem.cs (line 236, just after saveData.mainData.isLoadingGame = false;)
  • Got it. Thank you! I just wanted to make sure I wasn't missing something.
  • edited June 2014
    I'm not sure if this is the best place to post this question, so I'm sorry if it's not.. :-)

    I wrote my own Remember Script to be added to an Object that starts off in the scene "Inactive".  In my OnLoad Cutscene, I do some global variable checks and ultimately set this Object to active, however, I am not seeing the LoadData get executed on my Remember Script.

    Could this be a timing issue?  I looked through the SaveSytem.cs and it looks like ReturnMainData runs first (which includes running the OnLoad custscene), and then LevelStorage is ran (which as I understand where Remember Scripts run).

    So maybe I should modify my remember script specific stuff in the LevelStorage to yield or wait?  Any feedback on the best approach would be greatly appreciated!

    Thanks again for a really awesome plugin!
  • Oh, and I DO see SaveData get called and ran in my RememberScript... :-)
  • Timing shouldn't really be an issue.  Have you updated the LevelStorage script to unload the data in ReturnCurrentLevelData ()?

    I can't really give much advice other than "do as the others do".  Best strategy is really to just pick another RememberScript reference in the LevelStorage script and rename everything - the RememberName script is the easiest to go by.
  • I'll double Check everything, but I did use the other RememberScripts as a guide, and I have one custom one that works just fine already... the only different between the two are that my new one has this Active/Inactive condition.  If it should work fine I'll keep digging... wasn't sure if it was a limitation or not.

    Thanks for replying so quickly!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.