Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Alexejhero opened this issue Oct 28, 2022 · 1 comment
Labels
bug Something isn't working code health

Comments

@Alexejhero
Copy link

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 ItsDeltin added bug Something isn't working code health labels Feb 14, 2023
@ItsDeltin
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working code health
Projects
None yet
Development

No branches or pull requests

2 participants