Jump to content
Sign in to follow this  
BadAss -Mapfact.net-

The "Terminate" command

Recommended Posts

Just as the title says - I'ld like to know how it works.

The Biki's description isn't very telling, i think the syntax there is not really right.

For MP scripts we sometimes need the Server stuff like good old OFP:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?!local Server:exit

In the new sqf style scripts it doesn't seem to work. I'm just testing in SP, with "if condition then exit".

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if(local Server))then{exit};

player sidechat"Hallo";

In SP my Server logic is local on my machine, but the sidechat is displayed anyways. No exit.

As i'm doing:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if(local Server))then{terminate};

player sidechat"Hallo";

I'm getting error messages: "Error missing {" "Error then: type string, expecting Array, code"

As i'm doing:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if(local Server)then{hint "termi";terminate "TestTerminate.sqf"};

player sidechat "Hallo";

I'm getting the error message: "Error terminate: type string, expecting script"

So, how can I tell my script to exit when i want it to?  icon_rolleyes.gif  Any ideas, suggestions, experience?

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if !(local server) then {

player sidechat "Hallo";

};

EDIT:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (local server) exitwith {};

Share this post


Link to post
Share on other sites

Sorry, if I wasn't clear: to test the exiting of the 'script' i needed the condition to be true, because if it wasn't the script wouldn't quit anyway.

So i could have done<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_condi=true;

if(_condi)then{do_anything_to_cause_the_script_to_exit};

player sidechat "as i'm reading this, exiting didn't work too well.";

Hopefully that makes it clearer what i wanted to say in my good broken english. wink_o.gif

Share this post


Link to post
Share on other sites

Extrapolated, this should probably be:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if !(local server) then

{

terminate;

};

or one lined:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if !(local server) then {terminate;};

Share this post


Link to post
Share on other sites
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (local server) exitwith {};

Well, that's it. Thank you, it works fine. smile_o.gif

Didn't really notice this command to date. Pretty much new stuff to learn that kinda makes it interesting as well as frustrating sometimes. wink_o.gif

Share this post


Link to post
Share on other sites

For the record terminate is used with a script handle, like this:

Script.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">WaitUntil

{

Player SideChat Format ["Time %1",Time];

False

};

Called with:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Script=[] ExecVM "Script.sqs";

Sleep 5;

Terminate _Script;

Hint "Script.sqs has been terminated without any naff Arnie jokes";

Share this post


Link to post
Share on other sites

The terminate command is used to make a script terminate externally:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_script = execVM "test.sqf";

sleep 5;

terminate _script;

Actually, I'd prefer the first variant that Gaia posted due to clarity reasons *nudges ColonelSandersLite* wink_o.gif

Exiting a script somewhere in-between can often lead to situations where you're wondering why the script doesn't do what you want and you suddenly notice that you have an exit line somewhere where it doesn't belong.

There are cases where you'd have to run through a ton of other code in some deeply nested loops that can't be avoided, so the exitWith command has it's uses (Although those also tend to be the cases where it can cause the most trouble. That's why I'd always put a fat comment somewhere to remind me of the in-beween exit).

But if it can be avoided like with the simple restructuring in Gaia's example I'd always prefer this variant.

edit:

That teaches me to not take too long to post, as UNN just posted about the terminate command while I was typing smile_o.gif

Share this post


Link to post
Share on other sites

Actually, I'd prefer the first variant that Gaia posted due to clarity reasons *nudges ColonelSandersLite* wink_o.gif

I could be wrong but I think he edited that in while I was making my post (look at the edit dates). Either that, or I just missed it. I know my post there is wrong, but the correct conclusion is eventually reached elsewhere, and I'm just going to leave it for the sake of discussion.

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  

×