Page 1 of 1

Reset specific variable groups

Posted: Thu Jun 15, 2023 7:54 am
by munkbusiness
I know that we have the feature DialogueManager.ResetDatabase that resets the variables and quests to their initial values.

Would it be possible to target specific groups of variables to be reset while keeping the values of other. I have some variables that change each run of my roguelike and others that are permanent progression.
variableGroups.png
variableGroups.png (22.85 KiB) Viewed 620 times

Re: Reset specific variable groups

Posted: Thu Jun 15, 2023 9:18 am
by Tony Li
Hi,

You could just loop through the variables:

Code: Select all

foreach (var variable in DialogueManager.masterDatabase.variables)
{
    if (variable.title.StartsWith("rundata."))
    {
        if (variable.type == FieldType.Number) DialogueLua.SetVariable(variable.title, 0);
        else DialogueLua.SetVariable(variable.title, "");
    }
}

Re: Reset specific variable groups

Posted: Fri Jun 16, 2023 3:53 am
by munkbusiness
OK, so I would have to manually put in the string or number I want to reset to. There is no GetInitialValue or something like that I can use?

EDIT:
I think I found it thanks for the help.

Code: Select all

foreach (var variable in DialogueManager.masterDatabase.variables) {
            if (variable.Name.StartsWith("rundata.")) {
                if (variable.Type == FieldType.Number) DialogueLua.SetVariable(variable.Name, variable.InitialFloatValue);
                else if (variable.Type == FieldType.Text) DialogueLua.SetVariable(variable.Name, variable.InitialValue);
                else if (variable.Type == FieldType.Boolean) DialogueLua.SetVariable(variable.Name, variable.InitialBoolValue);
            }
        }

Re: Reset specific variable groups

Posted: Fri Jun 16, 2023 8:31 am
by Tony Li
Yup, that's exactly what I was going to type initially, and then I totally forgot. :oops: