ItsDeltin / Overwatch-Script-To-Workshop

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

Calling methods inside conditions will not refresh the argument variables before calling #413

Open Alexejhero opened 1 year ago

Alexejhero commented 1 year ago

If you call a custom method from a condition, the condition will be evaluated before the body of the rule, which sets the required arguments variables

rule: "Example"
Event.OnDeath
if (IsGameInProgress())
if (Attacker() != Victim())
if (IsWinning(Attacker()))
{
    // whatever
}

compiles to

rule("Example")
{

    event
    {
        Player died;
        All;
        All;
    }

    conditions
    {
        Is Game In Progress == True;
        Attacker != Victim;
        Value In Array(Global Variable(Scores), Slot Of(Player Variable(Event Player, Player))) >= Subtract(Count Of(Global Variable(HeroList)), 1);
    }

    // Action count: 10
    actions
    {
        Set Player Variable(Event Player, Player, Attacker);
        // whatever
    }
}

As such, this condition is evaluated incorrectly.

ItsDeltin commented 1 year ago

Sorry for the late response! You can use in parameters or macros so that the parameters are not set to a value.

// These do the exact same thing
// Macro
Boolean X(Number value): value + 2;

// Function
Boolean X(in Number value) {
    // This will output correctly as long as nothing inside the method generates actions.
    return value + 2;
}

OSTW will need to ensure that users don't generate actions in conditions