{"name":"BIS_fnc_loop","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","games":{"arma3":"1.16"},"since":"arma3 1.16","arma3_since":"1.16","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","params":[{"name":"action","type":"String","description":"can be one of:\n\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\"*","type_expr":"String"},{"name":"parameters","type":"Array","description":"used with \"itemAdd\" and \"itemRemove\" *action* (\"itemRemove\" only takes id):\n\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)","type_expr":"Array"}],"returns":{"type":"Nothing","type_expr":"Nothing"}}],"examples":[{"code":["// hints time every five seconds\n[\"itemAdd\", [\"uniqueId\", { hint str time; }, 5]] call BIS_fnc_loop;"]},{"code":["// removes stacked loop with id of uniqueId\n[\"itemRemove\", [\"uniqueId\"]] call BIS_fnc_loop;"]},{"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;"]},{"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;"]},{"code":["// hints time every frame\n[\"itemAdd\", [\"uniqueId\", { hint str time; }]] call BIS_fnc_loop;"]},{"code":["// remove item from loop with id \"uniqueId\"\n[\"itemRemove\", [\"uniqueId\"]] call BIS_fnc_loop;"]}],"see_also":["for","forEach","while"]}