Jump to content
Sign in to follow this  
1para{god-father}

what does if(true)exitWith{};

Recommended Posts

After a script I sometimes see :-

if(true)exitWith{};

i.e

ASfirstrun = true;

nul = [s1,"trans"] execVM "airSup\airSupInit.sqf";

if(true)exitWith{};

can somone please explain what this means just so i know !

Many thnaks

Share this post


Link to post
Share on other sites

At the very end of the script it is senseless since a sqf script will exit anyway at it's end.

if (condition) exitwith {code};

can be used to break from a while do loop, as example.

Share this post


Link to post
Share on other sites

I've seen that idium used inside a loop to force termination. Some other elements processed various cases and established the condition that was then used to decide whether to continue cycling through the loop.

Share this post


Link to post
Share on other sites

If can be used in the middle of a script (in it's main scope) to exit it, say i.e. the rest of the script doesn't fully work yet and it already contains block comments making it hard to comment the rest out.

At the end of a script, as [GLT]Myke says, it serves no purpose. I've seen it used, but I think it's just practice of using exit command in sqs scripts that somehow made it into sqf practice.

Share this post


Link to post
Share on other sites

Yeah, you're right. Should have mentioned that, sorry. I'm aware what it says, but I've never had it happen to me. Not sure how to read it either actually: sometimes it may exit the script, sometimes some other scope. How can it exit some other scope? A script can only be at one place at a time unless spawned/execVM'ed (correct me if I'm wrong here). Then again, I haven't had to rely on this method many times, only a few times during development of a script, never in the finished product.

Share this post


Link to post
Share on other sites
But what if the script with the exitWith is included to other one using #include?

I assume you will get the exact same result as if you had copied the included script into where you include it. Meaning if it is in the outermost scope then it will exit the script.

Share this post


Link to post
Share on other sites
I assume you will get the exact same result as if you had copied the included script into where you include it. Meaning if it is in the outermost scope then it will exit the script.

Yeah, #include pretty much means "paste the contents here".

In general before a script file is accessed by the interpreter it goes through a pre-processor.

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  

×