Game Development Community

checking for NULL str

by Ron Yacketta · in Torque Game Engine · 03/27/2002 (11:28 pm) · 5 replies

Folks,

Looking for a method to check if a string (client side scripting) is NULL. I have searched GG resources and forums (maybe not looking for the right key word?) and have turned up a NILL search

Regards,
Ron

#1
03/27/2002 (11:55 pm)
Now are you looking for an unitialized string, or a string that has nothing in it?

If the latter, "" is the equivilant (string literal?) remember. NULL is basically a nice way to check for 0. So substituting 0 for NULL might do the trick as well.

Why do you need to check for null strings? That might help us give you the answer or an alternative.
#2
03/28/2002 (12:16 am)
I know the difference :)

Instead of looking for NULL I flipped it to look for a value

if ( blah[%num] )
do something
#3
03/28/2002 (10:00 pm)
I don't think there's a way to actually come across a null string pointer in the scripting.

Undefined variables are the empty string if used in a string context, or zero if used in a numeric context.

And if you define a variable to be zero, and then use it in a string context, it will be interpreted as the string "0".
#4
07/24/2005 (4:30 am)
Sorry to bring back an old topic, but I was looking for a way to set a string as null. I have tried $foo = NULL (the string becomes "NULL"), $foo = "", $foo = 0, etc etc.
I also tried copying a null string to $foo and that didnt work either.

I could create a c++ function to delete a string but I would prefer to not have to do that if a way already exists.
#5
07/24/2005 (5:00 am)
You don't really want to be setting strings to null due to the way the string memory management system works, especially from script. Torque smart manages strings by using a stringTableEntry, and tracks references/dereferences to those strings as part of memory alloc/dealloc optimization.

Is there a specific functionality reason why you can't just set the string to "" in TScript?