no sitting avatar does not read as false

Creating scripts
Post Reply
Kru Ruk
Posts: 2
Joined: Mon May 18, 2020 2:50 pm
Has thanked: 2 times
Been thanked: 3 times

no sitting avatar does not read as false

Post by Kru Ruk »

(Sorry for the less than clear subject line.)

Here's the issue.
I am porting many scripts I have written elsewhere into Kitely.
I ran into a problem with detecting when the avatar stands up.

Code: Select all

            key sittingID = llAvatarOnSitTarget();
            llOwnerSay("sittingID " + (string) sittingID);
            if ((string) sittingID == NULL_KEY) {
                llOwnerSay("Is null key");
                if (sittingID) {
                    llOwnerSay("id did not read as false");
                }
                if (sittingID) {
                    llOwnerSay("normal check for no avatar sitting");
                }
                if ((key)NULL_KEY) {
                    llOwnerSay("weird check is still true.");
                }
            }
    
Here is the output from the experiment:
[19:08] object: sittingID 00000000-0000-0000-0000-000000000000
[19:08] object: Is null key
[19:08] object: id did not read as false
[19:08] object: normal check for no avatar sitting. THis should have been false
[19:08] object: weird check is still true.

The first line of output is expected for an avatar that just stood up. There is not avataronsit
The next line of out put is captured by my kluged test. Almost all other scripts just use if(av) expecting the 00000 thing to calculate as false.
But, when I do that standard if check it doesn't work. It still evaluates as true.
I then tried casting the NULL_KEY to key and found it also does not evaluate as false.

This is a new world in Kitely. Is there an owner setting that effects how NULL_KEY is evaluated?

I'm sure I am doing something extremely silly in the code.
I missed a turn and have entered into the Twilight Zone. Any clues would be appreciated.
These users thanked the author Kru Ruk for the post (total 3):
Ilan TochnerSelby EvansJohn Mela
User avatar
Ilan Tochner
Posts: 5218
Joined: Sun Dec 23, 2012 8:44 am
Has thanked: 2982 times
Been thanked: 3036 times
Contact:

Re: no sitting avatar does not read as false

Post by Ilan Tochner »

Hi Kru,

Try this:

Code: Select all

if (sittingID == NULL_KEY)
These users thanked the author Ilan Tochner for the post (total 2):
Selby EvansKru Ruk
User avatar
John Mela
Posts: 27
Joined: Tue Feb 04, 2014 9:50 pm
Has thanked: 28 times
Been thanked: 22 times

Re: no sitting avatar does not read as false

Post by John Mela »

A patch was submitted to fix this a while ago here:

http://opensimulator.org/mantis/view.php?id=5844

but it never made it to the main branch. It's a difficult one because it calls into question the whole nature of typing in LSL. My own opinion is that treating key values as strings is flawed design by Linden Lab (they should be integers), but we have to live with the legacy of that decision, and here we're seeing the results of that mistake back in 2001 or whenever.

So I agree with Ilan's recommendation, even if it might seem counter-intuitive (and incompatible with SL's behaviour).
These users thanked the author John Mela for the post (total 2):
Selby EvansKru Ruk
Kru Ruk
Posts: 2
Joined: Mon May 18, 2020 2:50 pm
Has thanked: 2 times
Been thanked: 3 times

Re: no sitting avatar does not read as false

Post by Kru Ruk »

Thanks for the replies.
I was just looking for a little clarity.
There were so many opensim scripts using the code fragment:

Code: Select all

key av = llAvatarOnSitTarget();
if (av) {
	// avatar is sitting do something
} else {
	// avatar just stood up, do something
}
It felt weird that so many people were using a code solution in published scripts that just plain fail in opensim.
So I wanted to double check.

I respect the workaround as a good one and add that to the list of stuff to do when migrating a script from SL to the world :)

Thanks again.
Much appreciated.
Post Reply