ItsDeltin / Overwatch-Script-To-Workshop

Converts scripts to Overwatch workshops.
208 stars 26 forks source link

'persist' Keyword #463

Open youyou-128 opened 1 year ago

youyou-128 commented 1 year ago

I noticed you used the 'persist' keyword in Pathmap, but there's no related documentation in the wiki. Can you tell me what it's used for?

ItsDeltin commented 1 year ago

The pathmap editor allows you to save & load your pathmaps (see the "How to save & load" section here) by copying the current global variable values in the inspector. The actions copied here can be pasted into a rule to load a save. Any global variables with the persist attribute will be included in the save.

For example:

// Include the players progress as part of the save game!
persist globalvar Number PlayerProgress = 0;

// Global variable containing an array of effects.
globalvar Any[] EffectArray = [];

If the player progresses through the game then saves the game with the action copy, the save will look something like this:

actions {
    Global.PlayerProgress = 5;
    Global.EffectArray = [Null, Null, Null, Null, Null, Null];
}

The player can load this save by pasting it into an empty rule. However, the PlayerProgress variable will get overridden with the default value, 0. To fix this, add a file called ds.toml to the root of the project and add this line: reset_nonpersistent = true. This will add some extra code to the workshop output to deal with this.

variables
{
    global:
        0: __loadPersist -- ostw generated variable: will be True if the player is loading a save.
        1: PlayerProgress
        2: EffectArray
}

-- ostw generated rule to assign variable defaults
rule("Initial Global")
{
    actions
    {
        -- Assigns defaults as normal.
        Set Global Variable(EffectArray, Empty Array);

        -- Any variables with the `persist` keyword has their initialization placed inside this If.
        -- These will not be given the default value if a save was loaded.
        If(Not(Global Variable(__loadPersist)));
            Set Global Variable(__loadPersist, True);
            Set Global Variable(PlayerProgress, 0);
        End;
    }
}

ds.toml is unfortunately another undocumented feature. It allows you to configure your project. Here are the other settings:

todo: get this info on the wiki