Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help with llListen

Bugstomper Shepherd
Registered User
Join date: 3 Mar 2007
Posts: 10
04-16-2008 07:00
Hello everyone,

i would like to use this script to allow my customers to change the prim color using chat commands on channel 5

default
{
state_entry()
{
llListen(5,"",llGetOwner(),"";);
}
listen(integer channel, string name, key id, string message)
{

if (llToLower(message) == "red";)
{
llSetColor(<0.7,0,0>, ALL_SIDES);
}
else if(llToLower(message) == "blue";)
{
llSetColor(<0,0,0.5>, ALL_SIDES);
}
else if(llToLower(message) == "green";)
{
llSetColor(<0,0.5,0>, ALL_SIDES);
}

}
}

Now, here's the issue. As long as i attach the object on my av or i rez it, the script works without problems but, when i send the object to someone else it does nothing at all.
Any suggestion would be really appreciated.
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
04-16-2008 07:22
changed(integer change)
{
if ( change & CHANGED_OWNER ) llResetScript();
}

This addition will work wonders!

happy scripting
_____________________
From Studio Dora
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
04-16-2008 07:30
Dora is quite correct.

The reason why that change is necessary is because, when you call llGetOwner(), it returns the ID of the owner at the time it is called, and then it is done. When the owner changes, the ID that's in the listen call doesn't.

Think about it this way - if you wrote this: y = 3; x = y + 4; y = 5; llOwnerSay(x); then you would expect the output to be 7. You would not say "the output should be 9 because x is y plus 4 and y is 5 now." It's just the same with llGetOwner(). Just because you used llGetOwner() to calculate the owner's key at some point in the past does not mean that the key magically updates itself if the owner changes in the future! :)
Bugstomper Shepherd
Registered User
Join date: 3 Mar 2007
Posts: 10
04-16-2008 07:33
Thank you Dora and Yumi! Works perfectly ;)
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
04-16-2008 10:55
You might also be interested in this recent thread...