Difference between "0" and null

Archive of the older Feature Request Forum Posts

Moderator: POL Developer

Locked
Danielle
Grandmaster Poster
Posts: 104
Joined: Tue Feb 07, 2006 3:32 pm
Location: Pittsburgh, Pennsylvania

Difference between "0" and null

Post by Danielle »

Simply enough, the ability for eScript to tell the difference between the number "0" and a variable that is "null" or "nothing".
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

Uhm these things already exist

( !value ) - works for all of the above

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

Post 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
Firedancer
Grandmaster Poster
Posts: 104
Joined: Fri Feb 03, 2006 6:32 am
Location: Austria
Contact:

Post 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*
Locked