Usage
Syntax: if(condition) { }
Explanation
Using the if language construct, you can perform conditional checks before executing code. The if construct can be paired with conditional statements, or can be left alone for a true/false check. If the condition is true, then the code is executed.
Conditional Statements
Statement | Definition |
x == y | x is equal to y |
x != y | x is not equal to y |
x > y | x is greater than y |
x >= y | x is greater than or equal to y |
x < y | x is less than y |
x <= y | x is less than or equal to y |
x in y[] | x is in array y |
!(statement) | Using ! means that the opposite of a statement is true |
x && y | x and y are true |
x || y | x or y is true |
Example
Using normal conditional statments:
if (player.account == "LoneAngelIbesu") { echo("Welcome, LoneAngelIbesu."); } if (player.account in {"Skyld", "LoneAngelIbesu", "Inverness"}) { echo("You are either Skyld, LoneAngelIbesu, or Inverness."); }
Using the exclamation point, you can check if a statement is the opposite:
if (!(player.account in {"Skyld", "LoneAngelIbesu", "Inverness"})) { echo("You are not Skyld, LoneAngelIbesu, or Inverness."); }
You can check if the result of a function is true or false like so:
if (functionName()) { echo("The function returned true."); } if (!functionName()) { echo("The function returned false."); }
You can check if a variable is true or false:
if (this.variable) { echo("The variable is true."); } if (!this.variable) { echo("The variable is false."); }
Categories
CategoryLanguageConstruct