Jump to content

Recommended Posts

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

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
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

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

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.

  • Like 1

Share this post


Link to post
Share on other sites

@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 sleepwaitUntil 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
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

@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
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

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

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
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

I absolutely agree with killzone_kid. The right choice of variable name - the main key to success! XD

 

UFOTest.jpg

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×