ZU23 2 Posted May 27, 2017 What do I write in the init to make a script loop forever? Share this post Link to post Share on other sites
beno_83au 1369 Posted May 27, 2017 while {true} do { //code }; Edit: it needs to be run in a scheduled environment (execVM, spawn) 2 Share this post Link to post Share on other sites
MKD3 27 Posted May 27, 2017 ^ youre gonna have a bad time without a sleep in there also. Share this post Link to post Share on other sites
beno_83au 1369 Posted May 27, 2017 1 hour ago, MKD3-FHI said: ^ youre gonna have a bad time without a sleep in there also. Perhaps, but that'd be within the //code part. And to further clarify my comment about the scheduled environment, if it's run in a non-scheduled environment (e.g. call) it'll only run for 10,000 iterations. After that it just stops, hence the execVM/spawn. 1 Share this post Link to post Share on other sites
MKD3 27 Posted May 27, 2017 Yeah just putting it out there Share this post Link to post Share on other sites
Mokka 29 Posted May 27, 2017 Maybe to specify this even more for you case, you should put the infinite loop in a separate script (let's call loop.sqf) and spawn/execVM this from within your init. // Unit init/init.sqf _loopHandle = spawn "loop.sqf"; //loop.sqf while {true} do { // Stuff here }; 1 Share this post Link to post Share on other sites
Mr_Sideburns 1 Posted June 2, 2017 On 27/05/2017 at 2:46 AM, beno_83au said: while {true} do { //code }; Edit: it needs to be run in a scheduled environment (execVM, spawn) Hi ! I'm trying to loop several animations in a mission I'm making. Would your solution works for looping this : []spawn { officierONU switchMove "HubBriefing_loop"; sleep 10.00; officierONU switchMove "HubBriefing_scratch"; sleep 10.00; officierONU switchMove "HubBriefing_think"; sleep 10.00; officierONU switchMove "HubBriefing_pointLeft"; sleep 10.00; }; They are running one after one other correctly but when the "pointLeft" one is done the unit keeps looping the first animation. Thanks in advance ! Share this post Link to post Share on other sites
7erra 629 Posted June 2, 2017 []spawn { while {true} do { officierONU switchMove "HubBriefing_loop"; sleep 10.00; officierONU switchMove "HubBriefing_scratch"; sleep 10.00; officierONU switchMove "HubBriefing_think"; sleep 10.00; officierONU switchMove "HubBriefing_pointLeft"; sleep 10.00; }; }; This does work if you meant it that way. In your script there's no loop, therefore the last animation you called is running infinitely. Spoiler Just some own thought: If someone wants a more dynamic animation then this script would add some more randomness: []spawn { while {true} do { _moves = ["HubBriefing_loop", "HubBriefing_scratch", "HubBriefing_think", "HubBriefing_pointLeft"]; _playMove = selectRandom _moves; officierONU switchMove _playMove; sleep (random 5 +10); }; }; Share this post Link to post Share on other sites
Mr_Sideburns 1 Posted June 3, 2017 Thanks mate ! I was trying to do something like a script with randomness. The way I understand the one you suggest, it will run infinitely the animations in a random order ? Is that how it works ? 18 hours ago, 7erra said: sleep (random 5 +10); Does this part means that the animation will change every 5 to 10sec on average ? Share this post Link to post Share on other sites
7erra 629 Posted June 3, 2017 []spawn { while {true} do { // The true condition can be changed to any value that returns true. Eg you can have a variable my_case_trueFalse which can be set to false if you want to stop the loop _moves = ["HubBriefing_loop", "HubBriefing_scratch", "HubBriefing_think", "HubBriefing_pointLeft"]; _playMove = selectRandom _moves; // select a random animation. chances are equal for every animation officierONU switchMove _playMove; sleep (random 5 +10); // waits at least 10 seconds and another 0-5 seconds. (so between 10 and 15 seconds) }; }; Here are some comments on my previous script to clarify. The loop runs infinitly, even after the unit dies (leads to some strange animations). 1 Share this post Link to post Share on other sites
Mr_Sideburns 1 Posted June 3, 2017 55 minutes ago, 7erra said: The loop runs infinitly, even after the unit dies (leads to some strange animations) It won't bother me for that mission (well, unless someone delibarately kill the unit). Is there a way to avoid this ? I'm still curious, I might need it for other missions Thanks Share this post Link to post Share on other sites
killzone_kid 1330 Posted June 3, 2017 On 5/27/2017 at 0:39 PM, Mokka said: Maybe to specify this even more for you case, you should put the infinite loop in a separate script (let's call loop.sqf) and spawn/execVM this from within your init. // Unit init/init.sqf _loopHandle = spawn "loop.sqf"; //loop.sqf while {true} do { // Stuff here }; 1. you cannot spawn a script by file name 2. even if you could, you cannot use spawn without an argument Share this post Link to post Share on other sites
pierremgi 4879 Posted June 3, 2017 56 minutes ago, Mr_Sideburns said: It won't bother me for that mission (well, unless someone delibarately kill the unit). Is there a way to avoid this ? I'm still curious, I might need it for other missions Thanks Just: while {alive officierONU} do { ..} instead of true; then add after this loop: officierONU switchMove ""; 1 Share this post Link to post Share on other sites
Mr_Sideburns 1 Posted June 4, 2017 1 hour ago, pierremgi said: Just: while {alive officierONU} do { ..} instead of true; then add after this loop: officierONU switchMove ""; Nice ! It looks so obvious sometimes when you see it Share this post Link to post Share on other sites
Markkos26 2 Posted December 10, 2018 On 3/6/2017 at 6:13 PM, 7erra said: []spawn { while {true} do { // The true condition can be changed to any value that returns true. Eg you can have a variable my_case_trueFalse which can be set to false if you want to stop the loop _moves = ["HubBriefing_loop", "HubBriefing_scratch", "HubBriefing_think", "HubBriefing_pointLeft"]; _playMove = selectRandom _moves; // select a random animation. chances are equal for every animation officierONU switchMove _playMove; sleep (random 5 +10); // waits at least 10 seconds and another 0-5 seconds. (so between 10 and 15 seconds) }; }; it's a great script. I just need to execute animations in order; not randomly but keeping the loop. Can you help me? Share this post Link to post Share on other sites
davidoss 552 Posted December 10, 2018 use AnimDone EH 1 Share this post Link to post Share on other sites
Markkos26 2 Posted December 10, 2018 3 minutes ago, davidoss said: use AnimDone EH ohh but how?... sorry scripting is not my best! Share this post Link to post Share on other sites
davidoss 552 Posted December 10, 2018 officierONU switchMove "HubBriefing_loop"; officierONU addEventHandler ["AnimDone", { params ["_unit", "_anim"]; // systemchat format ["Animation %1 ended",_anim]; if (!alive _unit) exitWith {_unit removeAllEventHandlers "AnimDone"}; switch (true) do { case (_anim == "HubBriefing_loop"): {_unit switchMove "HubBriefing_scratch"}; case (_anim == "HubBriefing_scratch"): {_unit switchMove "HubBriefing_think"}; case (_anim == "HubBriefing_think"): {_unit switchMove "HubBriefing_pointLeft"}; case (_anim == "HubBriefing_pointLeft"): {_unit switchMove "HubBriefing_loop"}; default {}; }; }]; 2 Share this post Link to post Share on other sites
Markkos26 2 Posted December 10, 2018 1 hour ago, davidoss said: officierONU switchMove "HubBriefing_loop"; officierONU addEventHandler ["AnimDone", { params ["_unit", "_anim"]; // systemchat format ["Animation %1 ended",_anim]; if (!alive _unit) exitWith {_unit removeAllEventHandlers "AnimDone"}; switch (true) do { case (_anim == "HubBriefing_loop"): {_unit switchMove "HubBriefing_scratch"}; case (_anim == "HubBriefing_scratch"): {_unit switchMove "HubBriefing_think"}; case (_anim == "HubBriefing_think"): {_unit switchMove "HubBriefing_pointLeft"}; case (_anim == "HubBriefing_pointLeft"): {_unit switchMove "HubBriefing_loop"}; default {}; }; }]; It works, but for any reason it doesnt when i use this animations: officierONU switchMove "Acts_JetsCrewaidR_idle"; officierONU addEventHandler ["AnimDone", { params ["_unit", "_anim"]; // systemchat format ["Animation %1 ended",_anim]; if (!alive _unit) exitWith {_unit removeAllEventHandlers "AnimDone"}; switch (true) do { case (_anim == "Acts_JetsCrewaidR_idle"): {_unit switchMove "Acts_JetsCrewaidRCrouch_in_m"}; case (_anim == "Acts_JetsCrewaidRCrouch_in_m"): {_unit switchMove "Acts_JetsCrewaidRCrouchThumbup_in_m"}; case (_anim == "Acts_JetsCrewaidRCrouchThumbup_in_m"): {_unit switchMove "Acts_JetsCrewaidRCrouchThumbup_loop_m"}; case (_anim == "Acts_JetsCrewaidRCrouchThumbup_loop_m"): {_unit switchMove "Acts_JetsCrewaidRCrouch_out_m"}; default {}; }; }]; Share this post Link to post Share on other sites
davidoss 552 Posted December 10, 2018 officierONU switchMove "Acts_JetsCrewaidR_idle"; officierONU addEventHandler ["AnimDone", { params ["_unit", "_anim"]; // systemchat format ["Animation %1 ended",_anim]; if (!alive _unit) exitWith {_unit removeAllEventHandlers "AnimDone"}; switch (true) do { case (_anim == "Acts_JetsCrewaidR_idle"): {_unit switchMove "Acts_JetsCrewaidR_idle_m"}; case (_anim == "Acts_JetsCrewaidR_idle_m"): {_unit switchMove "Acts_JetsCrewaidRCrouch_in_m"}; case (_anim == "Acts_JetsCrewaidRCrouch_in_m"): {_unit switchMove "Acts_JetsCrewaidRCrouchThumbup_in_m"}; case (_anim == "Acts_JetsCrewaidRCrouchThumbup_in_m"): {_unit switchMove "Acts_JetsCrewaidRCrouchThumbup_loop_m"}; case (_anim == "Acts_JetsCrewaidRCrouchThumbup_loop_m"): {_unit switchMove "Acts_JetsCrewaidRCrouchThumbup_out_m"}; case (_anim == "Acts_JetsCrewaidRCrouchThumbup_out_m"): {_unit switchMove "Acts_JetsCrewaidRCrouch_out_m"}; case (_anim == "Acts_JetsCrewaidRCrouch_out_m"): {_unit switchMove "Acts_JetsCrewaidR_idle_m"}; case (_anim == "Acts_JetsCrewaidR_idle_m"): {_unit switchMove "Acts_JetsCrewaidR_idle"}; default {}; }; }]; officierONU can not have weapons with this anim 4 1 Share this post Link to post Share on other sites
Markkos26 2 Posted December 10, 2018 12 minutes ago, davidoss said: officierONU can not have weapons with this anim Ohh thanks a ton dude! that was the problem!! 1 Share this post Link to post Share on other sites