OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: Mr.Peanut on 25 May 2007, 19:51:24

Title: Game logic script exits
Post by: Mr.Peanut on 25 May 2007, 19:51:24
I just read the following in the docs for BAS_f:
Quote
Please be aware that, due to the way ArmA works, the following code will not work (i.e. it will
not end the script if it is not being executed on a server):
if (!local BAS_Server_Logic) then {exit;};

Can anyone verify this and give an explanation?

Edit: Never mind. I just found the answer. The exit does not work with sqf scripts. For them you must use exitWith which does not require a then.

Code: [Select]
if (not local server) exitWith{}
Title: Re: Game logic script exits
Post by: DucusSumus on 30 May 2007, 19:37:48
Yup.

Also, Fer has told me that even the latter code is unreliable (he suggests putting everything you want to run server-side in a giant if (local server) statement), but I've never encountered any problems with it personally.  It always exits properly as far as I can tell. 
Title: Re: Game logic script exits
Post by: Mr.Peanut on 30 May 2007, 22:01:28
Supposedly, in sqf scripts exit will only exit the current code block scope. This true as well? Meaning the old method does not work because all it does is exit the if statement, not the script?
Title: Re: Game logic script exits
Post by: DucusSumus on 30 May 2007, 23:26:25
I think it's best never to use exit in sqf scripts.  Stick with if (true) exitWith {}.
Title: Re: Game logic script exits
Post by: h- on 31 May 2007, 10:15:24
AFAIK exit is not even 'seen' by the game in sqf..

Quote
Fer has told me that even the latter code is unreliable
I can concur.

Recently when I was writing a bit of a complex script I came across the fact that exitWith seems to work only on certain situations (not that I know which)..

For example this did not work:
Code: [Select]
if (_range < 60) then {if (!_err) exitWith {hint format ["blah blah",_grp,_range];};};The script continued normally after that..

I started using scopeName (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=s#scopeName) and breakOut (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=a#breakOut) which works like a charm.
Or at least worked, it has been couple of game versions since I have been tinkering with that script..

Script handle could not be used hence why terminate (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=t#terminate) was out of the question..