Forum rules - please read before posting.

Creating a global variable from code.

Hey, I was wondering if there is a way to generate a global (or other) variables on the fly. It doesn't need to be at run time, I just want to automate my variables generation.

Comments

  • You can create variables in bulk by clicking the cog icon beside the "Add Global variable" button, or create them through script:

    GVar newVariable = new GVar ();
    newVariable.label = "My bool";
    newVariable.type = VariableType.Boolean;
    newVariable.id = 3;
    KickStarter.variablesManager.vars.Add (newVariable);
    

    The main thing to be careful of is that your new variable's ID is unique. The GVar class has an optional constructors that takes an array of existing IDs to generate a new one. Such an array can be gotten with:

    private int[] GetIDArray ()
    {
        List<int> idArray = new List<int>();
        foreach (GVar variable in KickStarter.variablesManager.vars)
        {
            idArray.Add (variable.id);
        }
        idArray.Sort ();
        return idArray.ToArray ();
    }
    
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.