Difference between revisions of "BIS fnc loop"

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\|game([0-9])= *([^ ]+) * +\|version([0-9])= *([^ ]+) * " to "|game$1=$2 |version$3=$4 ")
m (Some wiki formatting)
 
(13 intermediate revisions by the same user not shown)
Line 23: Line 23:
 
* timer: [[Number]] - (Optional, default 0) delay between executions
 
* timer: [[Number]] - (Optional, default 0) delay between executions
 
* timerType: [[String]] - (Optional, default "seconds") can be "seconds" or "frames"
 
* timerType: [[String]] - (Optional, default "seconds") can be "seconds" or "frames"
* conditionStart: [[Code]] - (Optional, default {{ic|{ [[true]] <nowiki>}</nowiki>}}) will ''wait'' until the condition is met to start the code
+
* conditionStart: [[Code]] - (Optional, default <sqf inline>{ true }</sqf>) will ''wait'' until the condition is met to start the code
* conditionEnd:  [[Code]] - (Optional, default {{ic|{ [[false]] <nowiki>}</nowiki>}}) stops the loop as soon as the ending condition is met (after the end of ''code'')
+
* conditionEnd:  [[Code]] - (Optional, default <sqf inline>{ false }</sqf>) stops the loop as soon as the ending condition is met (after the end of ''code'')
 
* executeOnce: [[Boolean]] - (Optional, default [[false]])
 
* executeOnce: [[Boolean]] - (Optional, default [[false]])
  
 
|r1= [[Nothing]]
 
|r1= [[Nothing]]
  
|x1= <code>{{cc|hints time every five seconds}}
+
|x1= <sqf>// hints time every five seconds
["itemAdd", ["uniqueId", { hint str time; }, 5]] [[call]] [[BIS_fnc_loop]];</code>
+
["itemAdd", ["uniqueId", { hint str time; }, 5]] call BIS_fnc_loop;</sqf>
  
|x2= <code>{{cc|removes stacked loop with id of uniqueId}}
+
|x2= <sqf>// removes stacked loop with id of uniqueId
["itemRemove", ["uniqueId"]] [[call]] [[BIS_fnc_loop]];</code>
+
["itemRemove", ["uniqueId"]] call BIS_fnc_loop;</sqf>
  
|x3= <code>{{cc|hints time every frame after BIS_variable is assigned}}
+
|x3= <sqf>// hints time every frame after BIS_variable is assigned
["itemAdd", ["uniqueId", { [[hint]] [[str]] [[time]]; }, [[nil]], [[nil]], { ![[isNil]] { BIS_variable } }]] [[call]] [[BIS_fnc_loop]];</code>
+
["itemAdd", ["uniqueId", { hint str time; }, nil, nil, { !isNil { BIS_variable } }]] call BIS_fnc_loop;</sqf>
  
|x4= <code>{{cc|hints time every five seconds after BIS_variable is assigned}}
+
|x4= <sqf>// hints time every five seconds after BIS_variable is assigned
["itemAdd", ["uniqueId", { [[hint]] [[str]] [[time]]; }, 5, "seconds", { ![[isNil]] { BIS_variable } }]] [[call]] [[BIS_fnc_loop]];</code>
+
["itemAdd", ["uniqueId", { hint str time; }, 5, "seconds", { !isNil { BIS_variable } }]] call BIS_fnc_loop;</sqf>
  
|x5= <code>{{cc|hints time every frame}}
+
|x5= <sqf>// hints time every frame
["itemAdd", ["uniqueId", { [[hint]] [[str]] [[time]]; }]] [[call]] [[BIS_fnc_loop]];</code>
+
["itemAdd", ["uniqueId", { hint str time; }]] call BIS_fnc_loop;</sqf>
  
|x6= <code>{{cc|remove item from loop with id "uniqueId"}}
+
|x6= <sqf>// remove item from loop with id "uniqueId"
["itemRemove", ["uniqueId"]] [[call]] [[BIS_fnc_loop]];</code>
+
["itemRemove", ["uniqueId"]] call BIS_fnc_loop;</sqf>
  
|seealso= [[for]], [[forEach]], [[while]]
+
|seealso= [[for]] [[forEach]] [[while]]
 
}}
 
}}

Latest revision as of 12:58, 18 July 2022

Hover & click on the images for description

Description

Description:
Loop stacked code/function with timing and conditional control. Code and conditions are executed in non-scheduled environment.
Execution:
call
Groups:
Program Flow

Syntax

Syntax:
[action, parameters] call BIS_fnc_loop
Parameters:
action: String - can be one of:
  • "initialize" - Initializes game loop (not required as internal AUTO_INITIALIZE variable is set to true)
  • "terminate" - Terminates game loop (required as internal AUTO_TERMINATE variable is not set to true)
  • "itemAdd" - Adds an item to loop
  • "itemRemove" - Remove item from loop with id "uniqueId"
  • "onEachFrame" - internally used by "initialize"
  • "itemExecute" - internally used by "onEachFrame"
parameters: Array - used with "itemAdd" and "itemRemove" action ("itemRemove" only takes id):
  • id: String - loop unique id
  • code: Code or String - code to be executed
  • timer: Number - (Optional, default 0) delay between executions
  • timerType: String - (Optional, default "seconds") can be "seconds" or "frames"
  • conditionStart: Code - (Optional, default { true }) will wait until the condition is met to start the code
  • conditionEnd: Code - (Optional, default { false }) stops the loop as soon as the ending condition is met (after the end of code)
  • executeOnce: Boolean - (Optional, default false)
Return Value:
Nothing

Examples

Example 1:
// hints time every five seconds ["itemAdd", ["uniqueId", { hint str time; }, 5]] call BIS_fnc_loop;
Example 2:
// removes stacked loop with id of uniqueId ["itemRemove", ["uniqueId"]] call BIS_fnc_loop;
Example 3:
// hints time every frame after BIS_variable is assigned ["itemAdd", ["uniqueId", { hint str time; }, nil, nil, { !isNil { BIS_variable } }]] call BIS_fnc_loop;
Example 4:
// hints time every five seconds after BIS_variable is assigned ["itemAdd", ["uniqueId", { hint str time; }, 5, "seconds", { !isNil { BIS_variable } }]] call BIS_fnc_loop;
Example 5:
// hints time every frame ["itemAdd", ["uniqueId", { hint str time; }]] call BIS_fnc_loop;
Example 6:
// remove item from loop with id "uniqueId" ["itemRemove", ["uniqueId"]] call BIS_fnc_loop;

Additional Information

See also:
for forEach while

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