Statements & Loops
Conditional statements are used to perform different actions based on different conditions.
If a condition is true, you can perform one action and if the condition is false, you can perform another action.
- If - Commands to be executed if the specified condition is true.
- Else - Commands to be executed if the specified condition is false.
- And - All specified conditions need to be true.
- Or - At least one of the specified conditions needs to be true.
- Switch - Perform different actions based on different conditions (cases).
Difference between If/Else and Switch #
If/Else statement takes a specific condition and checks whether the condition is truthy or falsy. If the condition is true, then the if statement executes a specific code block. If the condition is false, then the else statement executes a different code block.
- Example of checking what color a viewer chose with If/Else:
If color == "green" { execute block of commands } Else if color == "yellow" { execute block of commands } Else if color == "blue" { execute block of commands } Else if color == "pink" { execute block of commands }
As you can see, you would need to nest multiple If/Else statements to check for all the possible colors. This could get quite unreadable.
Switch statement is a multiple-choice selection statement. You decide what to execute for each case.
- Example of checking what color a viewer chose with Switch:
Switch color Case green { execute block of commands } Case yellow { execute block of commands } Case blue { execute block of commands } Case pink { execute block of commands }
Using Switch statement for multiple conditions is so much easier to read! And if you have a lot of conditions to check, the execution should be also faster.
IF statement is used to specify a block of commands to be executed if a condition (or multiple conditions) is true.
Commands under ELSE statement are executed instead if a condition is false.
You can think of it as If something is true, then do something, otherwise do something else.
By pressing the + button, you can add:
- And - add another AND condition. All conditions must be true for the block to execute. If one of them is false, the whole IF statement will be also false and the ELSE block will be executed instead.
- Or - add another OR condition. At least one of the conditions must be true for the block to execute. If all of them are false, the whole IF statement will be also false and the ELSE block will be executed instead.
Box Name | Type | Description |
---|---|---|
Value | Left side of the comparison you want to evaluate. | |
Compare Type | Dropdown menu | Operator you wish to use to compare left and right side. |
Value | Whatever value you want to compare the left side with. |
Switch statement is used to select one of many blocks of commands to be executed based on single condition.
Add one Switch statement and then nest Case Statement commands inside for each case.
Use the + button in the Case Statement command to add more than one condition to the same Switch Statement.
Use ‘default’ as a Case Statement text if you want to execute an action when no other cases meet the conditions.
Box Name | Type | Description |
---|---|---|
Value | Expression to evaluate. Its result will be matched against each case you add. |
- Add a new Switch Statement command
- Decide what expression you want to evaluate.
For example, you would like to check the name of the viewer. - Add a Case Statement for each choice.
For example, add a Case Statement for Lioran, Melonax, Sebas and Cyanidesugar. - Under each Case Statement, decide what commands you want to execute.
For example, under Case Statement for Lioran, you want to play a specific sound effect. And under the Case Statement for Melonax, you want to play a different sound effect. - (Optional) Add a default case to execute a block of commands if no Case Statement matches the expression.
For example, if the viewer’s name isn’t Lioran, Melonax, Sebas or Cyanidesugar, play a default sound effect. -
Now every time the button is pressed, it will check the name of the viewer and execute one Case Statement command block matching their name (or execute the default block).
Commands inside the Re-enable block will be repeated for X number of times with X milliseconds of delay between each repeat.
You can use Break command to break (stop) the loop if certain conditions are met.
You can create some really cool effects with this command.
Delays that are entered into the Delay
field for commands within a Re-enable block will only work on the first loop. Delays will not work on any subsequent loops.
Box Name | Type | Description |
---|---|---|
Reactivate every (ms) | Int | Delay between each re-enable. If set to 0, it will repeat indefinitely. |
Amount | Int | How many times you want to re-enable the commands. Set to -1 for unlimited amount. |
Instantly repeats all the commands inside the block for a specified number of times.
For example, this is useful for instantly retrieving multiple values from File: Load Value/String or from Array: Pull command.
Box Name | Type | Description |
---|---|---|
Repeat amount | Int (number) | How many times you wish to repeat commands inside the block. |
If the condition is true, this command will break out of a Repeat or Re-enable statement, cancelling every command inside of the block if it hasn’t been executed yet.
Box Name | Type | Description |
---|---|---|
If Value | Left side of the comparison you want to evaluate. | |
Compare Type | Dropdown menu | Operator you wish to use to compare left and right side. |
Value | Whatever you want to compare the left side with. |
If the condition is true, it terminates all the commands and prevents them from happening until the button is pressed again.
Box Name | Type | Description |
---|---|---|
If Value | Left side of the comparison you want to evaluate. | |
Compare Type | Dropdown menu | Operator you wish to use to compare left and right side. |
Value | Whatever you want to compare the left side with. |