Skip to content

Switch Conditional

Switch Conditional

Evaluates multiple cases in order and executes the commands for the first case whose conditions are met.

Properties

System

Name Explanation Type
Default Commands The commands to execute when none of the switch cases match. Acts as the fallback or "else" branch. Script
Switch Items The list of cases in the switch conditional. Each case has its own conditions and commands to execute when matched. Array

Examples

Switch with Two Cases and a Default

This evaluates multiple cases in order. If Global Variable 0 equals 1, the first case executes. If it equals 2, the second case executes. Otherwise, the default block runs.

switch
{
    case ($gv[0] == 1)
    {
        wait(100);
    }
    case ($gv[0] == 2)
    {
        wait(200);
    }
    default
    {
        wait(500);
    }
}
{"Data":{"DefaultCommands":[{"$":"WaitCommand","Duration":{"IsGlobalVariable":false,"IsLocalVariable":false,"IsValue":true,"Value":"500","VariableIndex":0,"Metadata":null},"IsBlockingInput":false,"Metadata":null}],"SwitchItems":[{"Commands":[{"$":"WaitCommand","Duration":{"IsGlobalVariable":false,"IsLocalVariable":false,"IsValue":true,"Value":"100","VariableIndex":0,"Metadata":null},"IsBlockingInput":false,"Metadata":null}],"Conditions":[{"$":"VariableCondition","IsLocalVariable":0,"VariableIndex":0,"VariableComparison":0,"CompareToValue":{"IsGlobalVariable":false,"IsLocalVariable":false,"IsValue":true,"Value":"1","VariableIndex":0,"Metadata":null},"Metadata":null}],"IsDefaultSet":false,"Name":""},{"Commands":[{"$":"WaitCommand","Duration":{"IsGlobalVariable":false,"IsLocalVariable":false,"IsValue":true,"Value":"200","VariableIndex":0,"Metadata":null},"IsBlockingInput":false,"Metadata":null}],"Conditions":[{"$":"VariableCondition","IsLocalVariable":0,"VariableIndex":0,"VariableComparison":0,"CompareToValue":{"IsGlobalVariable":false,"IsLocalVariable":false,"IsValue":true,"Value":"2","VariableIndex":0,"Metadata":null},"Metadata":null}],"IsDefaultSet":false,"Name":""}],"Metadata":null},"TypeName":"MAR.Game.Shared.Models.Scripts.Commands.Flow.SwitchConditionalCommand"}

Switch with Named Cases

This uses named cases for editor readability. The name is a label that appears in the editor for organizational purposes.

switch
{
    case "Player is high level" ($gv[0] > 50)
    {
        wait(100);
    }
    default
    {
        wait(500);
    }
}
{"Data":{"DefaultCommands":[{"$":"WaitCommand","Duration":{"IsGlobalVariable":false,"IsLocalVariable":false,"IsValue":true,"Value":"500","VariableIndex":0,"Metadata":null},"IsBlockingInput":false,"Metadata":null}],"SwitchItems":[{"Commands":[{"$":"WaitCommand","Duration":{"IsGlobalVariable":false,"IsLocalVariable":false,"IsValue":true,"Value":"100","VariableIndex":0,"Metadata":null},"IsBlockingInput":false,"Metadata":null}],"Conditions":[{"$":"VariableCondition","IsLocalVariable":0,"VariableIndex":0,"VariableComparison":4,"CompareToValue":{"IsGlobalVariable":false,"IsLocalVariable":false,"IsValue":true,"Value":"50","VariableIndex":0,"Metadata":null},"Metadata":null}],"IsDefaultSet":false,"Name":"Player is high level"}],"Metadata":null},"TypeName":"MAR.Game.Shared.Models.Scripts.Commands.Flow.SwitchConditionalCommand"}