Page 1 of 1

Difference between "0" and null

Posted: Sat Mar 11, 2006 8:03 pm
by Danielle
Simply enough, the ability for eScript to tell the difference between the number "0" and a variable that is "null" or "nothing".

Posted: Sat Mar 11, 2006 10:01 pm
by Austin
Uhm these things already exist

( !value ) - works for all of the above

( value != 0 ) // Integer 0
( value != error ) // Error
( value != "" ) // empty string

Posted: Sun Mar 12, 2006 1:09 pm
by Marilla
The typical way I test where I need to differentiate between a 0 value and an error or null is this:

Code: Select all

If (!value && value != 0)
 'only runs on error
elseif (value == 0)
  'only runs if value is explicitly 0
else
  'etc
endif
You could also:

Code: Select all

If (value == error)
 'catches ALL errors, no matter the type
  print(cstr(error));
elseif (!value)
  'since error is trapped above, this would run on 0
else
  'etc
endif

Posted: Wed Mar 15, 2006 2:04 am
by Firedancer
forgot one option....

Code: Select all

if(value+1)
 //...then it's not error :P
endif
works too hehe. But I'd commonly not use it, it's not really nice-to-read code *g*