Results 1 to 5 of 5

Thread: Nul/nill/0 instead of nil as script handle

  1. #1

    Question Nul/nill/0 instead of nil as script handle

    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.

  2. #2
    CWR² Developer SaOk's Avatar
    Join Date
    Nov 23 2006
    Location
    Helsinki, Finland
    Posts
    1,309
    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.

  3. #3
    Second Lieutenant Celery's Avatar
    Join Date
    Apr 9 2003
    Location
    BI Forums
    Posts
    4,882
    Author of the Thread
    I did a test and nil does indeed seem to change instead of staying as nil.

  4. #4
    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

  5. #5
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •