Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
09-08-2005 22:12
I've seen this in some scripts, especially vehicles: key agent = llAvatarOnSitTarget(); if (agent) { if (agent != llGetOwner()) { // Bump the rider } else { // Owner sat down, turn on physics, sound, etc } } else { // Rider got off, turn off stuff }
Does this work, especially the part where it decides that the rider got off? If no one's sitting any more, agent will be NULL_KEY. Is the handler for the key data type smart enough to interpret if (agent) as if (agent == NULL_KEY), which, IMO, is what the check should be? Also, what about the null string, ""? Is if (agent) equivalent to if (agent == "" ? From a C perspective, it wouldn't be either one, because NULL_KEY and "" would both be non-null pointers, so if (agent) would return true for both of them. But I don't know how LSL works with the key data type.
|
a lost user
Join date: ?
Posts: ?
|
09-08-2005 23:35
Yes.. it's strange but it does work.
I don't honestly know 100% for sure but I'll take a stab at it say that the reason it works is that the NULL_KEY is the aboslute zero value of a key and anything other than NULL_KEY is not a zero-value. The same with "". In terms/context of strings, "" is the absolute zero-value.. or NULL value of a string and hence works as if it is equal to 0. However, I am pretty sure you can't go if(!agent) as it's not a boolean compatible variable type.
|
Sean Gorham
Stopped making sense
Join date: 5 Mar 2005
Posts: 229
|
09-08-2005 23:40
According to my reading of the wiki, a null string and NULL_KEY aren't the same thing. A NULL_KEY equates to "00000000-0000-0000-0000-000000000000". You'll probably want to test specifically for NULL_KEY. http://secondlife.com/badgeo/wakka.php?wakka=NULL_KEYhttp://secondlife.com/badgeo/wakka.php?wakka=Constants
|
a lost user
Join date: ?
Posts: ?
|
09-08-2005 23:51
Nope. They are definitely not the same thing (ie. "" does not equal NULL_KEY). And "" definitely does not equal 0, and NULL_KEY definitely does not equal 0 either. However: key test_key = NULL_KEY; string test_str = "";
default { state_entry() { if(test_key) llSay(0,"Key is not NULL_KEY"); else llSay(0,"Key is NULL_KEY");
test_key = llGetOwner(); if(test_key) llSay(0,"Key is not NULL_KEY"); else llSay(0,"Key is NULL_KEY");
// String if(test_str) llSay(0,"String is not NULL"); else llSay(0,"String is NULL");
test_str = llKey2Name(llGetOwner()); if(test_str) llSay(0,"String is not NULL"); else llSay(0,"String is NULL"); } } Output will be: Key is NULL_KEY Key is not NULL_KEY String is NULL String is not NULL Whereas: test_key = NULL_KEY;
default { state_entry() { if(!test_key) llSay(0,"Key is NULL_KEY"); else llSay(0,"Key is not NULL_KEY"); } } This will not compile throwing a type-mismatch error.
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
09-09-2005 00:04
Interesting. So this doesn't work like NULL pointers at all, but rather, some sense of a NULL/false value for the type. Or rather, some sense for a non-null/true/meaningful value for the type, since the inverted boolean check won't compile. Which makes sense, I guess, since LSL is all pass by value, so there's basically no concept of a pointer. I wonder what would happen if you put a key = "" in there and tested that too. I might try that out tomorrow. I suspect it'll fail the if(key) check. And I had an error in my original post (too late to think straight), it should have said agent != NULL_KEY, not agent == NULL_KEY. But you guys understood what I was trying to say  Edit: I just re-read your first post, and I basically repeated what you said. OK, I need to go get some sleep  Thanks.
|