Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Making Door script Listen on channel

Hiroku Kamachi
Registered User
Join date: 29 Jul 2007
Posts: 10
09-08-2007 04:41
I want to make my door script open and close with a button that says open or close on a channel. I can make the button, that is easy, but I can't make my door script listen on a channel to have the doors open or close. I will post the script. I hope someone can make it work.

CODE

default
{

touch_start(integer total_number)
{
rotation rot = llGetLocalRot();

if (rot.z == 1)
{
rot.z = 0.707107;
rot.s = -0.707107;
}
else
{
rot.z = 1;
rot.s = 0;
}
llSetLocalRot(rot);
}
}
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
09-08-2007 04:45
llListen will solve your problem:

http://www.lslwiki.net/lslwiki/wakka.php?wakka=llListen

if the door and then button are linked, llMessageLinked is better, because you don't need a listener:

http://www.lslwiki.net/lslwiki/wakka.php?wakka=llMessageLinked

HTH
Hiroku Kamachi
Registered User
Join date: 29 Jul 2007
Posts: 10
09-08-2007 14:09
I know that I need that in the script, I just don't know how to change it so that it listens instead of having to be touched.
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
09-09-2007 01:09
Well...

you need two pieces of code for this:

*** The Door-Button ***

CODE


integer channel = -123456; // Always use negative numbers for Object to Object-talk

default
{

state_entry()
{
// do nothing on rez :)
}

touch_start(integer total_number)
{
llSay(channel, "operate"); // Talk to the door
}

}


Hint: I only say «operate» because the door already decides whether it's open or closed.

Code for the door:

CODE


integer channel = -123456;
integer listen_handle;

default
{

state_entry()
{
// initialize the listener
// the listener will listen to everybody who touches the door-button (NULL_KEY)

listen_handle = llListen(channel, "", NULL_KEY, "");

}

listen(integer listen_channel, string name, key id, string message)
{

// only do something if the channel, where the message is received
// is equal to our listen channel and if the message is «operate»

if(listen_channel == channel && message == "operate")
{

// close or open the door (your original script)

rotation rot = llGetLocalRot();

if (rot.z == 1)
{
rot.z = 0.707107;
rot.s = -0.707107;
}
else
{
rot.z = 1;
rot.s = 0;
}
llSetLocalRot(rot);
}

}

}




HTH
Hiroku Kamachi
Registered User
Join date: 29 Jul 2007
Posts: 10
09-09-2007 01:23
thank you so much for that.