|
|
Line 1: |
Line 1: |
| {{Command|= | | {{Command|= Comments |
| ____________________________________________________________________________________________ | | ____________________________________________________________________________________________ |
|
| |
|
| | ofpr |= | | | ofp |= Game name |
|
| |
|
| |1.85|= | | |1.00|= Game version |
| ____________________________________________________________________________________________ | | ____________________________________________________________________________________________ |
|
| |
|
| | 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. |= | | | Returns the current time acceleration factor |= Description |
| ____________________________________________________________________________________________ | | ____________________________________________________________________________________________ |
|
| |
|
| | '''if''' (condition) '''then''' if_code '''if''' (condition) '''then''' if_code '''else''' else_code |= | | | '''accTime''' |= Syntax |
|
| |
|
| |p1= condition: [[Boolean]] - either a variable or any comparison or code that returns either true or false |= | | | [[Number]] |= Return value |
| | |
| |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><nowiki>if (canFire tank) then {grp1 setCombatMode "BLUE"} else {grp1 setCombatMode "RED"}</nowiki></code> '''Example 2:'''<code><nowiki>_text = if (alive player) then {"alive"} else {"not alive"}hint _text</nowiki></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><nowiki>? alive player : hint "yes"</nowiki></code> This code is completely valid, while you have to add the brackets, if you want to use the 'if ... then' syntax:<code><nowiki>if (alive player) then {hint "yes"}</nowiki></code> Â |=
| |
| ____________________________________________________________________________________________ | | ____________________________________________________________________________________________ |
| | | |
| |x1= <code><nowiki>if (!canFire tank) then {grp1 setCombatMode "RED"}</nowiki></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. |= | | |x1= <pre>_acc = accTime</pre> |= Example 1 |
| ____________________________________________________________________________________________ | | ____________________________________________________________________________________________ |
|
| |
|
| | |= | | | [[setAccTime]] |= See also |
|
| |
|
| }} | | }} |
| | |
| | <h3 style="display:none">Notes</h3> |
| <dl class="command_description"> | | <dl class="command_description"> |
| <!-- Note Section BEGIN --> | | <!-- Note Section BEGIN --> |
Line 36: |
Line 28: |
| <!-- Note Section END --> | | <!-- Note Section END --> |
| </dl> | | </dl> |
| | |
| | Old Comments (temporary): |
| | |
| | Use [[setAccTime]] to change the time acceleration factor. Not to be confused with [[skipTime]]. |