Hardrock/Sandbox – User
Jump to navigation
Jump to search
Description
- Description:
- Syntax with One Code BlockThis structure checks for a condition and executes a code block, if the condition equals true. Additionally you may define a code block, which is executed if the condition equals false.
- Groups:
- Uncategorised
Syntax
- Syntax:
- if (condition) then if_code if (condition) then if_code else else_code
- Parameters:
- condition: Boolean - either a variable or any comparison or code that returns either true or false
- if_code: String - the code, which is executed if the condition equals true. The code is usually written in curly braces ('{', '}'), but you may also use quotes (see String Notation). You have to seperate different commands with a semicolon (';'). The rules for code blocks are equal to those for functions (see Chapter 2. Functions (*.sqf)). Variables used in code blocks have to defined previously, otherwise they will be deleted after its execution.
- condition: Boolean - either a variable or any comparison or code that returns either true or false
- if_code: String - the code, which is executed if the condition equals true. See above for the code block syntax.
- else_code: String - the code, which is executed if the condition equals false. See above for the code block syntax.
- Return Value:
- Return value needed
Examples
- Example 1:
if (!canFire tank) then {grp1 setCombatMode "RED"}
Note You have to take care, that combined conditions are embraced by parenthesises. Wrong: if (alive player) && (someAmmo player) then {hint "yes"} Right: if ((alive player) && (someAmmo player)) then {hint "yes"}Syntax with Two Code BlocksYou may define another code block, which is executed if the condition doesn't fulfill.
Additional Information
- See also:
- See also needed
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note