Forum rules - please read before posting.
Tech questions during the weekend? Drop in on the community Discord channel!

global popup variables to store int arrays

edited May 2017 in Technical Q&A
Hi! I was just wondering how the popup variable works in script. 

Basically I'm in need of saving a few groups of ints (for a List of Data classes. Each data class only holds ints, 10 ints). Now, I need 7 groups of ints (they're basically date's information, like, month, year, day of the week, weather type, etc). I was thinking how I could save these using AC globals in a clean way (I don't want to make 70 single int variables if possible). So, the first thing that came to mind were the popup variables. But I notice they are strings, not ints. So I'm not sure how that'd go since I've never used that variable type in script. Is it possible to return an array with the whole data? or would I need to get the data one by one?

Else, what is the way that AC deals with saving global variable data? I have some code I can use to serialize Data classes but I've never had to deal with profiles before. I mostly leave that to AC. Plus, I've no clue how AC is dealing with profiles itself, and it worries me saved data won't be in sync with AC's profiles.

Anyone has any tips to deal with this situation?

Anyway, any advice will be greatly appreciated.

Comments

  • PopUp strings are only used in the initial declaration and UI - so far as saving goes, they're ignored and only the integer value is actually saved.  A PopUp variable is really more like a string array, where an index pointing to a single entry is saved.

    You can store anything in the String type, as you can convert integers to strings with .ToString(), and use parsing (e.g. int.TryParse) to convert them back.  You can also merge integers together by separating them with e.g. a colon, and then splitting them into an array when loading.

    Per-profile / Options data is stored in PlayerPrefs, to keep them independent from save game data.  You can set a Global Variable to be recorded in Options data from the Variables Manager - see this tutorial.
  • edited May 2017
    Thanks, I was considering that technique, but I wanted to make sure there wasn't any built-in method I could use to save my custom data classes. Anyway, I though all global variables data was saved when saving, guess I was wrong? (None of my projects are far enough to care much about saving yet so I haven't tested it- for now I'm mostly building some features I plan to use in all of my personal projects).

    By the way, more or less related, but, how do you create/delete AC global variables in-Editor? I have some editor functionality that is used to create Characters data (different types of stats and other stuff), so I'd like to be able to automatically create their AC global variable on the fly. I'm kinda doing the same already with UI, because some features I'm coding require several menus created in the Menu manager (helps me when starting new projects). Though, I guess I can just take a look at the source code for that (though, I prefer not to when possible).
  • They are saved, so long as they're not linked to Options Data.  If they are, then they're stored in the PlayerPrefs as per-profile data.  You'd have to call Options.SavePrefs() to save changes in that case.

    Global Variables are stored within the "vars" GVar List in Variables Manager.  You don't need to open the source code, as it's in the scripting guide:

    AC.KickStarter.variablesManager.vars
  • Oh, so linking them to Options data makes sure each profile uses separate data for each global variable? That's cool to know.

    Then about creating Gvars. So I just add new Gvar class objects to the list then? I was asking because with the UI I had to make sure they were not only initialized but saved (else they were forgotten when the editor was restarted), so I wasn't sure if I had to do something similar with newly created Gvars.
  • Nothing unique to AC - you have to flag up the class as dirty, but that's true when serializing any Unity data:

    EditorUtility.SetDirty (AC.KickStarter.variablesManager);

    More info here: https://docs.unity3d.com/ScriptReference/EditorUtility.SetDirty.html
  • Hey, thanks! I've heard of the SetDirty method, but I'm still new to serialization, so I didn't really think about it, lol. Guess I got confused because the UI needed AssetDatabase methods. 

    Anyway, cheers!
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.
Do NOT follow this link or you will be banned from the site!