Home   Help Search Login Register  

Author Topic: Word of caution on the use of "Nil" and UAV  (Read 2161 times)

0 Members and 1 Guest are viewing this topic.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Word of caution on the use of "Nil" and UAV
« 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

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
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: Word of caution on the use of "Nil" and UAV
« Reply #1 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

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: Word of caution on the use of "Nil" and UAV
« Reply #2 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?
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: Word of caution on the use of "Nil" and UAV
« Reply #3 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 :)

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: Word of caution on the use of "Nil" and UAV
« Reply #4 on: 22 Aug 2010, 20:50:46 »
Thanks for the info  :good:
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: Word of caution on the use of "Nil" and UAV
« Reply #5 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.

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Word of caution on the use of "Nil" and UAV
« Reply #6 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 :)
try { return true; } finally { return false; }

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
Re: Word of caution on the use of "Nil" and UAV
« Reply #7 on: 28 Aug 2010, 14:32:56 »
To delete a variable, should i use the following method ?

variable = nil;

just for clarification

Regards,
HRN1992
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(

Offline i0n0s

  • Moderator
  • *****
Re: Word of caution on the use of "Nil" and UAV
« Reply #8 on: 28 Aug 2010, 16:13:45 »
Yes