Reset specific variable groups

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
munkbusiness
Posts: 10
Joined: Wed Jun 14, 2023 10:33 am

Reset specific variable groups

Post 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 619 times
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Reset specific variable groups

Post 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, "");
    }
}
munkbusiness
Posts: 10
Joined: Wed Jun 14, 2023 10:33 am

Re: Reset specific variable groups

Post 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);
            }
        }
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Reset specific variable groups

Post by Tony Li »

Yup, that's exactly what I was going to type initially, and then I totally forgot. :oops:
Post Reply