Jump to content
Sign in to follow this  
Spudgunner

Are SQF scripts read once only?

Recommended Posts

Are SQF files read once scripts or are they read continously?

The reason I'm asking is that I'm using an IF statement to detect a when a WP number is reached, but the condition never come true as the script has stopped processing.

Share this post


Link to post
Share on other sites

They are ran completely and once at the time they are called. Sleep, waituntil etc of course affects what it does and how long it takes to finish it.

You run a script when you need something done. If you want to simulate a trigger with script then run it and add waituntil {condition here} inside it and it will stop the execution of the script there until given condition is true.

Share this post


Link to post
Share on other sites
They are ran completely and once at the time they are called. Sleep, waituntil etc of course affects what it does and how long it takes to finish it.

You run a script when you need something done. If you want to simulate a trigger with script then run it and add waituntil {condition here} inside it and it will stop the execution of the script there until given condition is true.

Thanks. What if I put use a While-Loop for the part I need to check and always make the condition true. Would that keep the script running?

Share this post


Link to post
Share on other sites

Yes, just don't forget to add some sleep inside the loop.

Share this post


Link to post
Share on other sites

As far as I know, it's usually a better and easier to use waitUntil {condition} rather than a loop that keeps checking the condition every X seconds.

Share this post


Link to post
Share on other sites

I'd disagree, fully depends on the context.

waitUntil checks the condition every frame (to my knowledge) so if you are not aiming for an instant result use while loop with a sleep instead.

Share this post


Link to post
Share on other sites
As far as I know, it's usually a better and easier to use waitUntil {condition} rather than a loop that keeps checking the condition every X seconds.

I dont see how checking a condition every frame can better than while and longer sleep. There are few situations - if any aside from hardcore realtime scripts - where you need instant response. The performance gains from using a while when it comes to single-shot "triggers" (which generally dont need to be checked instantly) should be significant.

Not sure I agree about it being easier either...

waitUntil {condition}

while {!condition} do { sleep }

Pretty much the same "difficulty" IMO.

Share this post


Link to post
Share on other sites

Or, you could just sleep the waituntil and it wont check every frame?

waituntil {sleep 5; !alive something};

Share this post


Link to post
Share on other sites

Which is little different to

while {not alive something} do {sleep 5} ;

Except that the while version has the advantage that it won't sleep at all if the condition is true on entry.

Share this post


Link to post
Share on other sites

If the condition is simple there is no real difference between checking whether the sleep time is over as opposed to checking your condition. So unless you're using a super-complex condition there is no real reason not to check it every frame. Heck I was using a group marker script that updates all marker positions every frame and didn't notice any performance hit, so just checking even a non-trivial condition every frame shouldn't cause any issues. Regardless, remember that sleep is also checked every frame - the engine needs to know when the time is up to reactivate the script.

Share this post


Link to post
Share on other sites

so I tried using:

while {alive gb1} do
{
gb1 say"boss3";
gb1 globalchat"blah blah";
sleep 10;
gb1 say"boss4";
gb1 globalchat"blah blah";
};
hint "not alive";

If I shoot the boss while he is saying the first line, he still says the 2nd line after 10 seconds. If I don't shoot him, the whole thing repeats forever until I shoot him. I want to be able to check if he is alive before saying each line and then end the script or bypass a section if he isn't. Would I have to use .sqs for this?

Share this post


Link to post
Share on other sites

No. If you can't figure out how to do stuff with just IFs etc, there is always scopeName + breakTo to simulate SQS's goto

Share this post


Link to post
Share on other sites
Would I have to use .sqs for this?

You never need to use sqs ;)

In your case the solution is simply to replace the while with an if. Not sure why you'd even choose while to begin with, of course that will loop until he's dead... And yes the loop will continue with the last two lines if you shoot him during the sleep, while doesnt check its condition again until after execution of the entire loop.

Share this post


Link to post
Share on other sites

Thank you. Sorry for my noobness. I search as much as I can before posting. My knowledge on scripting is very limited. I just found the guide by Cheetah Basics of SQF so hopefully I will have less posts to annoy you with :P

Share this post


Link to post
Share on other sites

Sounds like you're off to a great start! When you have more questions, don't be afraid to ask! :)

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
Sign in to follow this  

×