OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: laggy on 22 Aug 2010, 13:22:15

Title: Word of caution on the use of "Nil" and UAV
Post by: laggy on 22 Aug 2010, 13:22:15
Many times I have used this solution when calling scripts:

nil = execVM "myscript.sqf"

When editing my last mission "1-7 Blood of the Sun" I found that the UAV kept malfunctioning. You could use it once but the second time you used it you where thrown out of the UAV mode and where stuck in black and white graphics. It was very frustrating and I had to debug my mission for days. I thought it was a BIS bug but sure enough, as soon as I stopped using "nil" when calling scripts everything worked fine.

Bug Report Link on BI Forum (http://forums.bistudio.com/showthread.php?t=105970)

I have read somewhere that you should never use "nil" to call scripts, but I see people do it all the time and I never found a reason not to, until now.

Laggy
Title: Re: Word of caution on the use of "Nil" and UAV
Post by: JamesF1 on 22 Aug 2010, 16:11:52
I've always made use of what I'd probably class as a 'bug', and assigned to zero, e.g.:
Code: [Select]
0 = execVM "myscript.sqf"It doesn't error, it doesn't change the value of zero, and it simply... works.  There's no danger of redefining another variable or reserved keyword, and even to someone reading the code (who is unfamiliar with SQF) it becomes relatively obvious, relatively quickly, that it's just used for discarding the handle.

Normally, in a language, I'd expect this to error or, maybe (but I'd cringe), to allow zero to be re-assigned to the new value (have fun with maths, after evaluating 0=1, kids) - but the way BIS have allowed this has given me a useful way to 'throw away' script handles :D
Title: Re: Word of caution on the use of "Nil" and UAV
Post by: laggy on 22 Aug 2010, 16:37:00
Do you know why just putting:

execVM "myscript.sqf"

- in a trigger returns an error, if you put that in i.e init.sqf it works fine?
Title: Re: Word of caution on the use of "Nil" and UAV
Post by: JamesF1 on 22 Aug 2010, 17:24:34
Because triggers (and other such constructs, such as a unit's init line) are not allowed to return a value (I imagine simply because it serves no purpose, as it doesn't return to anything).  Technically, BIS could just update the SQF parser/compiler to allow such constructs, and simply discard any return statements, but it just seems they've chosen to make it a little more explicit :)
Title: Re: Word of caution on the use of "Nil" and UAV
Post by: laggy on 22 Aug 2010, 20:50:46
Thanks for the info  :good:
Title: Re: Word of caution on the use of "Nil" and UAV
Post by: kju on 23 Aug 2010, 07:11:21
I suggest:
_nul or _dump

For unit init lines you need GV unfortunately.
Yet to simplify editing, I'd recommend to script everything outside the sqm/editor.

PS: CBA and squint detect the malicious nil assignment.
Title: Re: Word of caution on the use of "Nil" and UAV
Post by: Worldeater on 26 Aug 2010, 12:32:25

Quote from: http://community.bistudio.com/wiki/nil
Never ever assign a value to nil!

Doing so creates a global variable with the same name that overrides the "command" nil:
Code: [Select]
foo = "foo";
nil = "bar";
foo = nil;
hint foo; // displays "bar"

HTH :)
Title: Re: Word of caution on the use of "Nil" and UAV
Post by: haroon1992 on 28 Aug 2010, 14:32:56
To delete a variable, should i use the following method ?

variable = nil;

just for clarification

Regards,
HRN1992
Title: Re: Word of caution on the use of "Nil" and UAV
Post by: i0n0s on 28 Aug 2010, 16:13:45
Yes