Hardrock/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 2: Line 2:
____________________________________________________________________________________________
____________________________________________________________________________________________


| ofp |=
| ofpr |=


|1.00|=
|1.85|=
____________________________________________________________________________________________


|arg= local |=
| 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. |=
____________________________________________________________________________________________


|eff= global |=
| '''if''' (condition) '''then''' if_code '''if''' (condition) '''then''' if_code '''else''' else_code |=
____________________________________________________________________________________________
 
|p1= condition: [[Boolean]] - either a variable or any comparison or code that returns either true or false |=


| Make a unit to perform an action. Use the List of Actions for reference about the available actions and their syntax. |=
|p2= 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. |=
____________________________________________________________________________________________


| '''action ''' |=
|p3= condition: [[Boolean]] - either a variable or any comparison or code that returns either true or false |=


|p1= unit: [[Object]] |=
|p4= if_code: [[String]] - the code, which is executed if the condition equals true. See above for the code block syntax. |=


|p2= action: [[Array]] |=
|p5= else_code: [[String]] - the code, which is executed if the condition equals false. See above for the code block syntax. |=


| [[Nothing]] |=
| [[Any Type]] -  If the condition is fulfilled, the last given value of the if_code code block is returned (if not followed by a semicolon). Else [[Nothing]] is returned. [[Any Type]] If the condition is fulfilled, the last given value of the if_code code block, else the last given value of the else_code code block is returned (if not followed by a semicolon).'''Example 1:'''<code>if (canFire tank) then {grp1 setCombatMode "BLUE"} else {grp1 setCombatMode "RED"}</code> '''Example 2:'''<code>_text = if (alive player) then {"alive"} else {"not alive"}hint _text</code> outputs the message "alive", if the player is alive, and "not alive" if not.Additional Syntax in Scripts OFP's scripting language provides another language structure with a similar task: '? condition : code'. This structure may be only used in scripts although (see [[Chapter 1. Scripts (*.sqs)]]). It is less strict than 'if ... then'; for 'if ... then' conditions have to be embraced by two brackets, while for '? ... :' they don't.<code>? alive player : hint "yes"</code> This code is completely valid, while you have to add the brackets, if you want to use the 'if ... then' syntax:<code>if (alive player) then {hint "yes"}</code>   |=
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= <code>soldier action ["eject", vehicle soldier]</code> |=
|x1= <code>if (!canFire tank) then {grp1 setCombatMode "RED"}</code> 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. |=
____________________________________________________________________________________________
____________________________________________________________________________________________



Revision as of 04:44, 1 August 2006

Hover & click on the images for description

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