Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

GetOwner better

Dr Debruyere
Anna
Join date: 12 Jul 2008
Posts: 43
08-07-2008 09:53
For some reason my script will not listen to others after I give it to them. I am a noob scripter. Maybe I have implemented the 11GetOwner function incorrectly?

state_entry()
{
llListen(7,"", llGetOwner(), "";); //Listen to my owner on channel 7
}

The script worked when I used Null_Key in place of getowner. It still works for me, but when someone else becomes the owner it does not work.

Anna
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-07-2008 11:26
The problem is that you are executing the call to llListen() once, and at the time you call it, llGetOwner() returns YOUR key. So forever on the script will be listening to only that key. What you need to do is remove the old listen (to you) and start another listen (to the new owner) when the owner changes. Some people just reset the entire script, having it start as if you had just compiled it. That may be okay for small simple scripts, but it is not always what you want.

Here is what it looks like if you want to restart the listen without resetting:

CODE

integer listenHandle = 0;

default
{
state_entry()
{
listenHandle = llListen(7, "", llGetOwner(), "");
}

changed(integer changes)
{
if (changes & CHANGED_OWNER)
{
llListenRemove(listenHandle);
listenHandle = llListen(7, "", llGetOwner(), ""); // llGetOwner() will now be the NEW owner
}
}
}


Here is what it looks like if you just want to reset the whole script:

CODE

integer listenHandle = 0;

default
{
state_entry()
{
listenHandle = llListen(7, "", llGetOwner(), "");
}

changed(integer changes)
{
if (changes & CHANGED_OWNER)
{
llResetScript();
}
}
}


Good luck!

http://www.lslwiki.net/lslwiki/wakka.php?wakka=changed
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llListen
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llListenRemove
Dr Debruyere
Anna
Join date: 12 Jul 2008
Posts: 43
Thank You
08-07-2008 13:27
Thank you for helping. This is why I love the SL community!