{"name":"BIS_fnc_loop","operator":null,"title":"BIS fnc loop","type":"function","url":"https://community.bistudio.com/wiki/BIS_fnc_loop","revid":328958,"updated":"2022-07-18T10:58:38Z","groups":["Program Flow"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"1.16"}],"since":{"game":"arma3","name":"Arma 3","version":"1.16"},"arma3_since":"1.16","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Loop stacked code/function with timing and conditional control. Code and conditions are executed in non-scheduled environment.","syntaxes":[{"syntax":"[action, parameters] call BIS_fnc_loop","since":null,"effect":null,"exec":null,"params":[{"name":"action","type":"String","optional":false,"default":null,"description":"can be one of:\n- \"initialize\" - Initializes game loop (not required as internal AUTO_INITIALIZE variable is set to true)\n- \"terminate\" - Terminates game loop (required as internal AUTO_TERMINATE variable is *not* set to true)\n- \"itemAdd\" - Adds an item to loop\n- \"itemRemove\" - Remove item from loop with id \"uniqueId\"\n- *\"onEachFrame\" - internally used by \"initialize\"*\n- *\"itemExecute\" - internally used by \"onEachFrame\"*","types":["String"],"since":null,"text":"action: String - can be one of:\n- \"initialize\" - Initializes game loop (not required as internal AUTO_INITIALIZE variable is set to true)\n- \"terminate\" - Terminates game loop (required as internal AUTO_TERMINATE variable is *not* set to true)\n- \"itemAdd\" - Adds an item to loop\n- \"itemRemove\" - Remove item from loop with id \"uniqueId\"\n- *\"onEachFrame\" - internally used by \"initialize\"*\n- *\"itemExecute\" - internally used by \"onEachFrame\"*"},{"name":"parameters","type":"Array","optional":true,"default":"0","description":"used with \"itemAdd\" and \"itemRemove\" *action* (\"itemRemove\" only takes id):\n- id: String - loop unique id\n- code: Code or String - code to be executed\n- timer: Number -  delay between executions\n- timerType: String - (Optional, default \"seconds\") can be \"seconds\" or \"frames\"\n- conditionStart: Code - (Optional, default `{ true }`) will *wait* until the condition is met to start the code\n- conditionEnd:  Code - (Optional, default `{ false }`) stops the loop as soon as the ending condition is met (after the end of *code*)\n- executeOnce: Boolean - (Optional, default false)","types":["Array"],"since":null,"text":"parameters: Array - used with \"itemAdd\" and \"itemRemove\" *action* (\"itemRemove\" only takes id):\n- id: String - loop unique id\n- code: Code or String - code to be executed\n- timer: Number - (Optional, default 0) delay between executions\n- timerType: String - (Optional, default \"seconds\") can be \"seconds\" or \"frames\"\n- conditionStart: Code - (Optional, default `{ true }`) will *wait* until the condition is met to start the code\n- conditionEnd:  Code - (Optional, default `{ false }`) stops the loop as soon as the ending condition is met (after the end of *code*)\n- executeOnce: Boolean - (Optional, default false)"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"}}],"examples":[{"text":"```sqf\n// hints time every five seconds\n[\"itemAdd\", [\"uniqueId\", { hint str time; }, 5]] call BIS_fnc_loop;\n```","code":["// hints time every five seconds\n[\"itemAdd\", [\"uniqueId\", { hint str time; }, 5]] call BIS_fnc_loop;"]},{"text":"```sqf\n// removes stacked loop with id of uniqueId\n[\"itemRemove\", [\"uniqueId\"]] call BIS_fnc_loop;\n```","code":["// removes stacked loop with id of uniqueId\n[\"itemRemove\", [\"uniqueId\"]] call BIS_fnc_loop;"]},{"text":"```sqf\n// hints time every frame after BIS_variable is assigned\n[\"itemAdd\", [\"uniqueId\", { hint str time; }, nil, nil, { !isNil { BIS_variable } }]] call BIS_fnc_loop;\n```","code":["// hints time every frame after BIS_variable is assigned\n[\"itemAdd\", [\"uniqueId\", { hint str time; }, nil, nil, { !isNil { BIS_variable } }]] call BIS_fnc_loop;"]},{"text":"```sqf\n// hints time every five seconds after BIS_variable is assigned\n[\"itemAdd\", [\"uniqueId\", { hint str time; }, 5, \"seconds\", { !isNil { BIS_variable } }]] call BIS_fnc_loop;\n```","code":["// hints time every five seconds after BIS_variable is assigned\n[\"itemAdd\", [\"uniqueId\", { hint str time; }, 5, \"seconds\", { !isNil { BIS_variable } }]] call BIS_fnc_loop;"]},{"text":"```sqf\n// hints time every frame\n[\"itemAdd\", [\"uniqueId\", { hint str time; }]] call BIS_fnc_loop;\n```","code":["// hints time every frame\n[\"itemAdd\", [\"uniqueId\", { hint str time; }]] call BIS_fnc_loop;"]},{"text":"```sqf\n// remove item from loop with id \"uniqueId\"\n[\"itemRemove\", [\"uniqueId\"]] call BIS_fnc_loop;\n```","code":["// remove item from loop with id \"uniqueId\"\n[\"itemRemove\", [\"uniqueId\"]] call BIS_fnc_loop;"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["for","forEach","while"],"notes":[],"categories":["Arma 3: Functions","Arma 3: New Functions","Function Group: Program Flow","Functions","Introduced with Arma 3 version 1.16"],"docblock":null,"filled_from_docblock":[]}