Documentation
Conditional

Conditional

You can create a conditional statement by using the Condition element.

scene1.action([
    Condition
        // if (persistent.get("favoriteTea") === "green")
        .If(persistent.equals("favoriteTea", "green"), [
            character1.say`You like green tea!`
        ])
])

In the condition statement, the game context is provided, you can learn more about the ScriptCtx object.

You can only have 1 If Statement and 1 Else Statement in a condition statement, but you can have multiple Else If Statements.

scene1.action([
    Condition
        .If(/* ... */, [/* ... */])
 
        .ElseIf(/* ... */, [/* ... */])
        .ElseIf(/* ... */, [/* ... */])
        .ElseIf(/* ... */, [/* ... */])
 
        .Else(/* ... */, [/* ... */])
])

Note: If you put these statements in the wrong order, the condition will throw an error.

Persistent is a good way to store data in the game context.

const persis = new Persistent<{ flag: boolean; }>("persis", { flag: false });
scene.action([
    persis.set("flag", true),
 
    Condition
        .If(persis.isTrue("flag"), [
            character1.say("Flag is true")
        ])
]);