BlacKnightBK 47 Posted February 26, 2017 Hello, I decided to read the description of the while loop and noticed that it says it is limited to 1000 iterations in a non-scheduled environment and unlimited in a scheduled environment. My question is what is does that mean and sorry if it is a stupid question. Thank you Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted February 26, 2017 According to KKs comment: When you call a while loop it's limited to 10.000 iterations, not 1.000. If you use spawn or execVM there's no such limit. Scheduled simply means a code being run by the execVM/spawn command, or by a call command which inherits from a scheduled command. As example in the init.sqf: SchedulerTest = {systemchat format ["CanSuspend: %1",canSuspend]}; _nonscheduled = [] call SchedulerTest; //false _scheduled = [] spawn SchedulerTest; //true _scheduled = [] spawn {_totallyscheduled = [] call SchedulerTest}; //true You can test for scheduled/nonscheduled with the canSuspend command. Edit: As serena and KK stated, the above is wrong and should return true in all three cases, since init.sqf is within scheduled environment. Sorry for the inconvenience! Cheers Share this post Link to post Share on other sites
BlacKnightBK 47 Posted February 26, 2017 3 minutes ago, Grumpy Old Man said: According to KKs comment: When you call a while loop it's limited to 10.000 iterations, not 1.000. If you use spawn or execVM there's no such limit. Scheduled simply means a code being run by the execVM/spawn command, or by a call command which inherits from a scheduled command. As example in the init.sqf: SchedulerTest = {systemchat format ["CanSuspend: %1",canSuspend]}; _nonscheduled = [] call SchedulerTest; //false _scheduled = [] spawn SchedulerTest; //true _scheduled = [] spawn {_totallyscheduled = [] call SchedulerTest}; //true You can test for scheduled/nonscheduled with the canSuspend command. Cheers hmm, Thanks, I think I get it Share this post Link to post Share on other sites
gc8 970 Posted February 26, 2017 you need to know when script can be suspended when working with commands like sleep and waituntil. they only work in suspendable environment (such as spawn and execVM. Share this post Link to post Share on other sites
MrCopyright 107 Posted February 26, 2017 A general rule of thumb is to use the spawn command if there is script suspension or indefinite loops inside it and to use the call command if there are not. 1 Share this post Link to post Share on other sites
serena 150 Posted February 26, 2017 @BlacKnightBK, your question can be simplified to: what the difference between the scheduled and non-scheduled environments. In scheduled environment you can execute continuously running scripts, use sleep / waitUntil commands, and scheduler take care of your script is working in parallel with other and each fairly received his portion of CPU performance. In non-scheduled environment executing script can not be interrupted or put to sleep. Continuously running script just freeze your game and cause an error. So, scripts executing in non-scheduled environment should be short and quick. @Grumpy Old Man, init.sqf executed in scheduled environment. So, all three calls return "Can Suspend: True" Share this post Link to post Share on other sites
killzone_kid 1326 Posted February 26, 2017 2 hours ago, serena said: @Grumpy Old Man, init.sqf executed in scheduled environment. So, all three calls return "Can Suspend: True" 8 hours ago, Grumpy Old Man said: _nonscheduled = [] call SchedulerTest; //false Share this post Link to post Share on other sites
serena 150 Posted February 26, 2017 @killzone_kid, Grumpy Old Man says: As example in the init.sqf: // init.sqf (it is important!) SchedulerTest = {systemchat format ["CanSuspend: %1",canSuspend]}; _nonscheduled = [] call SchedulerTest; //false _scheduled = [] spawn SchedulerTest; //true _scheduled = [] spawn {_totallyscheduled = [] call SchedulerTest}; //true // Output: // CanSuspend: true // CanSuspend: true // CanSuspend: true I did something wrong? Share this post Link to post Share on other sites
igneous01 19 Posted February 26, 2017 Recommend this wiki entry from BISim:https://resources.bisimulations.com/wiki/Script_Interruption In VBS case, spawn/execVM is threaded, and they have a command noInterrupt as a mutex to synchronize data access. It's probably the case for Arma as well. Share this post Link to post Share on other sites
killzone_kid 1326 Posted February 26, 2017 19 minutes ago, serena said: Grumpy Old Man says: As example in the init.sqf: 19 minutes ago, serena said: _nonscheduled = [] call SchedulerTest; //false So this ^^^ is correct, right? Is scheduled? true. Is nonscheduled? false. Share this post Link to post Share on other sites
serena 150 Posted February 26, 2017 I can say only one thing: init.sqf is executed in scheduled environment. Nothing else. :) Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted February 27, 2017 That's true, mistake on my part. Thanks for the correction. Edited my post to prevent further confusion. Cheers Share this post Link to post Share on other sites
serena 150 Posted February 28, 2017 Also interesting information about initialization order and executing environment: Initialization_Order Share this post Link to post Share on other sites
killzone_kid 1326 Posted February 28, 2017 18 hours ago, Grumpy Old Man said: That's true, mistake on my part. Thanks for the correction. Edited my post to prevent further confusion. Cheers Just for the record. I never said it was wrong, in fact I was trying to say the opposite. The comments were correct. The only problem with the function not returning anything to assign to variables, but the correspondence between the variable name and boolean in comment is spot on. Share this post Link to post Share on other sites
serena 150 Posted February 28, 2017 I absolutely agree with killzone_kid. The right choice of variable name - the main key to success! XD Share this post Link to post Share on other sites