adapap / OWScript

Python-like scripting language which transpiles into Overwatch Workshop script rulesets.
MIT License
37 stars 2 forks source link

Fix array items from non-constant arrays being transpiled to the value they were defined with #32

Closed netux closed 4 years ago

netux commented 4 years ago

... instead of a stack of Value In Array(...)s

Note that this only changes the behavior of non-constant variables. For optimization purposes, and since constants can't be modified, accessing an element on a constant array still transpiles to the value they were given on initialization.

Example

Rule
    Actions
        gvar global_array = [ 0, Null, False ]
        global_array[0]
        global_array[1]
        global_array[2]

        // old behavior
        const const_array = [ 0, Null, False ]
        const_array[0]
        const_array[1]
        const_array[2]

transpiles to

rule("") {
    Actions {
        Set Global Variable At Index(A, 1, Append To Array(Append To Array(Append To Array(Empty Array, 0), Null), Null));
        Value In Array(Value In Array(Global Variable(A)), 1, 0);
        Value In Array(Value In Array(Global Variable(A)), 1, 1);
        Value In Array(Value In Array(Global Variable(A)), 1, 2);

        0;
        Null;
        False;
    }
}

Fixes #31