Jump to content
Sign in to follow this  
celery

Nul/nill/0 instead of nil as script handle

Recommended Posts

I've seen a lot of people using disposable script handles like nul, nill or 0, but what exactly is the reason nil isn't used? I've used nil as a spawn handle in numerous simultaneous loops and other things, and so far there hasn't been a single conflict.

Share this post


Link to post
Share on other sites

I have heard that the best would be to use "local" _nul. My guess is that if you use nil the system may mix the orginal meaning of nil.

Share this post


Link to post
Share on other sites

I did a test and nil does indeed seem to change instead of staying as nil.

Share this post


Link to post
Share on other sites

If you create a global variable nil, either by assigning a script handle to it or another value, you "overwrite" the engine nil.

Now if you want to mark a variable for the VM to be collected with nil, for example somearray = nil, you assign the script handle to somearray.

An isNil "somearray" check will then always return false as somearray points to the scripthandle, means it isn't nil and you can't nilify a variable anymore.

The same is true for player. player = 0 will create a global variable called player.

If you use player in a script the global variable with value 0 is used instead of the engine player reference.

Xeno

Share this post


Link to post
Share on other sites

Yeah basically any engine variable will get messed up when you assign a new value for it, so you should avoid it in order to not break scripts that might use that variable.

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  

×