Page tree
Skip to end of metadata
Go to start of metadata



Introduced in

Version:3.7

Description

Description:

Executes the specified code, depending on the result of a defined condition. (Expansion of if...then...else functionality - see its page for details).

The elseif section is only executed if its specific condition is met, and multiple elseif sections, as well as an else section can be defined in an if...then construct:

if (trueCondition) then 
{
  trueCode; // executed if 'trueCondition' returns true
} 
elseif (elseCondition1) then 
{
  elseCode1; // executed if 'elseCondition1' returns true
} 
elseif (elseCondition2) then 
{
  elseCode2; // executed if 'elseCondition2' returns true
} 
else 
{
  falseCode; // executed if neither 'trueCondition' nor any of the 'elseConditions' are true
};


Syntax

Syntax:if (trueCondition) then {trueCode} elseif (elseCondition) then {elseCode} else (falseCode)
Parameters:
  • trueCondition: Boolean - Expression (code or variable) returning true or false.
  • trueCode: Code - Code to be executed if 'conditionA' returns true.
  • elseCondition: Boolean - Expression (code or variable) returning true or false.
  • elseCode: Code - Code to be executed if 'conditionA' returns true. (Multiple 'elseCondition' / 'elseCode' segments can be used.
  • falseCode: Code - Code to be executed if 'conditionN' returns false. Can be omitted if the preceding 'else' statement is left out as well.
Return Value:Anything - Value returned by either 'trueCode' or 'falseCode'.

Examples

Examples:
if (getDammage player == 0) then {
  hint "no damage";
} elseif (getDammage player < 0.3) then {
  hint "damage is less than 0.3";
} elseif (getDammage player < 1) then {
  hint "player is not dead yet";
} else {
  hint "player is dead";
};

Additional Information

See also: if...then...else, switch, Control Structures
Multiplayer: 
Problems: 

Notes