Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to make a script in one object listen to another object?

Hanumi Takakura
Registered User
Join date: 24 May 2006
Posts: 57
07-24-2006 14:56
Hello. Been seacrhing around the wiki and tutorials for days now. Call me dumb, but I can't get this to work. I'm trying to make a script for the star wars comunity, specifically, the opensource LCK lightsaber. It would make your saber appear on the hip when not used, and on the hand when used. I managed to compile two scripts for this, using the chat commands.

Script 1 for the actual saber, wich would go in each and every prim of the hilt object.
CODE

//vector saberColor;

default
{
link_message(integer sender_num, integer num, string msg, key id)
{
if(msg == "OFF")
{
llSetAlpha(0,ALL_SIDES);
}
else if(msg == "ON")
{
llSetAlpha(1,ALL_SIDES);
}
}
}


Script 2 wich goes in the hilt wich will be used on the hip of the avatar, or turneed off.

CODE

default
{
state_entry()
{
key owner = llGetOwner();
llListen(0,"",owner,"");
}

listen( integer channel, string name, key id, string message )
{
if( message == "/ls on" )
{
llSetStatus(STATUS_PHANTOM, TRUE);
llSetAlpha(0,ALL_SIDES);
}
if( message == "/ls off" )
{
llSetStatus(STATUS_PHANTOM, FALSE);
llSetAlpha(1,ALL_SIDES);
}
}
}


This system, also has a HUD, the hud has an on off button, the on hand saber works properly on this button because it's attatched to the rest of the LCK system. Here's the script inside that button.

CODE

integer channel = 72;

integer LSON = FALSE;
string text;
default
{
touch_start(integer total_number)
{
if(LSON == TRUE)
{
llSay(channel,"/ls off");
llSetColor(<1,1,0>,ALL_SIDES);
text = "Lightsaber Off";
llSetText(text,<1,1,1>,1);
LSON = FALSE;


}
else if(LSON == FALSE)
{
llSay(channel,"/ls on");
llSetColor(<0,1,0>,ALL_SIDES);
text = "Lightsaber On";
llSetText(text,<1,1,1>,1);
LSON = TRUE;


}

}
link_message(integer sender,integer num,string msg,key id)
{
if(msg == "HIDE")
{
llSetAlpha(0,ALL_SIDES);
llSetText("",<1,1,1>,1);
state hidden;
}
}
}

state hidden
{
link_message(integer sender,integer num,string msg,key id)
{
if(msg == "SHOW")
{
llSetAlpha(1,ALL_SIDES);
llSetText(text,<1,1,1>,1);
state default;
}
}
}


My problem is, that I don't know how to make the hip part listen to this button and the owner only. I can just remove the "owner" string on the IIListen part of the hip script but that way anyone can turn on and off my weapon at will. Please help.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
07-24-2006 15:18
I'd advise you to look at llSetLinkAlpha if you want to make an entire object appear or disappear - it's much easier and more efficient than having scripts in each prim.

That aside, if you want to have a listen that triggers only for the owner or objects owned by the owner, what you want to use is llGetOwnerKey.

CODE

listen(integer channel, string name, key id, string msg)
{
if (llGetOwnerKey(id) == llGetOwner()) {
// do stuff
}
}

llGetOwnerKey returns the avatar's key if it's said by an av, so that will only activate if either the owner or an object owned by the owner says anything.

If you're going to put the owner's key into a variable, make sure you have something that resets the key if the owner changes! e.g.
CODE

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

Personally I use llGetOwner() whenever I want to find out the owner's key, it's not much of a strain on the script.
Hanumi Takakura
Registered User
Join date: 24 May 2006
Posts: 57
07-24-2006 15:25
Thank you. I will work with this and post the results later. I'm right now in-world and with a scripter friend of mine. I'm not much of a scripter myself. :)

UPDATE: Here's the code I made.

CODE

default
{
state_entry()
{
key owner = llGetOwner();
llListen(0,"",owner,"");
}

listen( integer channel, string name, key id, string msg )
{
if (llGetOwnerKey(id) == llGetOwner())
{
if( msg == "/ls on" )
{
llSetLinkAlpha(0,0,ALL_SIDES);
}
if( msg == "/ls off" )
{
llSetLinkAlpha(0,1,ALL_SIDES);
}
}
}
}


it still works only if said by the avatar, not by the button. What do I need now?
Jolan Nolan
wannabe
Join date: 12 Feb 2006
Posts: 243
07-24-2006 17:06
On a game I'm working on I have a hud that controls your pieces with 'touch_start' in each button. It then says the command on a channel that only those buttons and your pieces listen to. It's something along the lines of:
CODE

touch_start(integer piece1)
{
llSay(37, "move up");
}

I'm probably missing something here but it uses touch instead of typing :o

- Jolan
Hanumi Takakura
Registered User
Join date: 24 May 2006
Posts: 57
07-24-2006 17:51
From: Jolan Nolan
On a game I'm working on I have a hud that controls your pieces with 'touch_start' in each button. It then says the command on a channel that only those buttons and your pieces listen to. It's something along the lines of:
CODE

touch_start(integer piece1)
{
llSay(37, "move up");
}

I'm probably missing something here but it uses touch instead of typing :o

- Jolan


It would work. But, the thing is, the button and HUD is a separate project in the open. Many have this script already. I'm adapting my script to it so people doesnt have to touch the hud script for anything. Now. the hud sends it's message on channel 72. if I put channel 72 on my script, it still does nothing.