Hardrock/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
m (Erentar moved page Hardrock's Sandbox to User:Hardrock/Sandbox: Bot: Moved page)
 
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Command|=
== Notes to myself ==
____________________________________________________________________________________________


| ofpr |=
[ ] reorganize ofp section
[ ] maybe introduce new category "Reference Lists" for lists like actions, EHs, configs?
[ ] extend getting started in bi wikiing page - reading


|1.85|=
____________________________________________________________________________________________


| 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. |=
[[Category:Sandbox]]
____________________________________________________________________________________________
 
| '''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 |=
 
|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. |=
 
|p3= condition: [[Boolean]] - either a variable or any comparison or code that returns either true or false |=
 
|p4= if_code: [[String]] - the code, which is executed if the condition equals true. See above for the code block syntax. |=
 
|p5= else_code: [[String]] - the code, which is executed if the condition equals false. See above for the code block syntax. |=
 
| [[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>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. |=
____________________________________________________________________________________________
 
|  |=
 
}}
<dl class="command_description">
<!-- Note Section BEGIN -->
 
<!-- Note Section END -->
</dl>

Latest revision as of 03:00, 3 December 2018

Notes to myself

[ ] reorganize ofp section
[ ] maybe introduce new category "Reference Lists" for lists like actions, EHs, configs?
[ ] extend getting started in bi wikiing page - reading