Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Passing key types from one trigger to another. :)

Jacqueline Bancroft
Registered User
Join date: 10 Sep 2004
Posts: 19
09-25-2004 01:57
Hi there :)

I'm hoping that someone here can help me.. ;)


I'm trying to figure out how to pass the information contained in a key from my "touch_start" trigger to my "listen" trigger. The key contains the llDetectedKey of the person that touched it. It asks that person a question using llDialog, and then returns the person's choice to "listen". I would like to then have my script give something to the person that clicked it, but I can't figure out how to tell my script the name of the person, from inside "listen." Any help would be appreciated. Thanks!

Jacqueline Bancroft
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
09-25-2004 02:38
HI Jac

probable the easest, and most iffishent way to pass a key from one event to another event would be the use of a global value.

then you could place a simple if statment inside listen to check if the person who says some thing has the same key as the person who touches the key.

ie
key userID = NULL_KEY;
string anser = "";

defolt
{
touch_start()
{
userID = llDetectedKey();
llListen( 0, "", NULL_KEY, "" );
llSay(0, "What is your favorit color?" );
}

listen( integer channel, string name, key id, string message )
{
if ( userID == id )
{
anser = message;
}
}
}


but there is another way as well. This way involves not rquire the global userID;
string anser = "";

defolt
{
touch_start()
{
key userID;
userID = llDetectedKey();
llListen( 0, "", userID, "" );
llSay(0, "What is your favorit color?" );
}

listen( integer channel, string name, key id, string message )
{
anser = message;
}
}


Personally I like having a global userID. and I also like to shut down my lissons when done. So I'd do some thing like.

key userId = NULL_KEY;
integer ears = 0;
string anser = "";

defolt
{
touch_start()
{
userID = llDetectedKey();
ears = llListen( 0, "", userID, "" );
llSay(0, "What is your favorit color?" );
}

listen( integer channel, string name, key id, string message )
{
anser = message;
llListenRemove(ears);
}
}

please pardon the sudo code. But it's late at night. and I dont' want to log in. and double check my code. I hope it is legable? ^.^
Jacqueline Bancroft
Registered User
Join date: 10 Sep 2004
Posts: 19
hrm
09-25-2004 07:33
I guess my problem is that the llDialog is the one speaking, so can it pass along the information of the clicking person thru that? I might as well just post the code I'm having trouble with:

key giver;


default
{
state_entry()
{


}

touch_start(integer total_number)
{
key giver;
giver = llDetectedKey(0);


llDialog(giver, "Would you like to receive your Top-Secret Information? (Warning, you can only do this once, and then your package will self destruct.)", [ "Open", "Keep Sealed" ], 1234);

llListen(1234,"","","Open";);
llListen(1234,"","","Keep Sealed";);

}

listen(integer channel,string name, key id, string message)
{
if(message == "Open";)
{
llWhisper(0, "Prepare to recieve your top secret info!";);
llGiveInventory(llDetectedKey(0), "Top-Secret Info";);
llRemoveInventory("Top-Secret Info";);
llRemoveInventory("Info Giver Script";); //this script
llWhisper(0, "Enjoy!";);
}
else if (message == "Keep Sealed";)
{
llWhisper(0, "You keep your package unopened... for now.";);
}
}
}

Here's what I'm trying to do:

1) Person that owns the package clicks the package.
2) This person gets a dialog box that asks "Would you like to receive your Top-Secret Information? (Warning, you can only do this once, and then your package will self destruct.)",
a) If player clicks Open button, they receive a notecard with information. Script then removes the notecard and its own script from the package's inventory, leaving object empty, but not itself deleted.
b) If player clicks Keep Sealed, they hear a whisper that says "You keep your package unopened... for now.". The notecard with information and the script stay inside the object for another time.
3) I haven't implemented it yet, but I can tell it'll give me trouble: I want to make it so that no one but the owner of the object can use the Dialog box.. if anyone else touches the object, nothing happens.

Thanks for your help Kurt, and I thank anyone else that can help me with this problem. :)
Xylor Baysklef
Scripting Addict
Join date: 4 May 2003
Posts: 109
09-25-2004 08:10
A couple of things:

First, the easy answer to your solution is just to use "id" in your listen event. This is the equivalent to using llDetectedKey, since when you use an llDialog it is actually the avatar speaking. No need for a global in that case.

Secondly, it looks like you are initializing another local variable called "giver" in your touch_start event. This is the problem ^_~. When assigning the llDetectedKey to this, it is using the local variable and ignores the global variable. Remove the "key giver;" line in your touch_start event. Then, in your listen event, replace your llDetectedKey with "giver". Of course, this is a lot of work to just get the same key that "id" is giving =). (You can also use the "name" parameter; this will be the person who responded to the dialog as well).

Xylor
McWheelie Baldwin
Registered User
Join date: 9 Apr 2004
Posts: 154
09-28-2004 12:24
Xylor is correct, the easiest way is to just use name and id from the listen event. This would eliminate the need for the global giver variable entirely.

Adding if(llGetOwner() != giver){ return; } in your touch_start handler will prevent others from seeing the dialog box. You could also reverse the if statement and put the dialog display code inside the statement instead of returning. Either way.

Also in your listen handler you may want to remove the listener set up for the dialog box. To do this create a global variable such as integer lid; then in your touch_start when you set up the listener add lid = llListen(...); so in your listen event you can do a llListenRemove(lid); This will prevent the listeners from persisting and causing problems down the road.

Hope this helps,
McW
McWheelie Baldwin
Registered User
Join date: 9 Apr 2004
Posts: 154
09-28-2004 12:38
Jacqueline,
Here is your script with the discussed changes. Note that I only moved the dialog msg to a global variable to keep the code from doing that crazy super wide screen thing it does. You can leave the text in the call to llDialog(). :D The text in red is where I made the notable changes. I hope this helps.

McW


CODE

integer lid;
string msg = "Would you like to receive your Top-Secret Information? "
+ ";(Warning, you can only do this once, and then your package "
+ "will self destruct.)";

default
{
touch_start(integer total_number)
{
key giver;
giver = llDetectedKey(0);
if(giver == llGetOwner())
{
lid = llListen(1234,"",giver,"";);
llDialog(giver, msg, [ "Open", "Keep Sealed" ], 1234);
}
}

listen(integer channel,string name, key id, string message)
{
llListenRemove(lid);
if(message == "Open";)
{
llWhisper(0, "Prepare to recieve your top secret info!";);
llGiveInventory(id, "Top-Secret Info";);
llRemoveInventory("Top-Secret Info";);
llRemoveInventory("Info Giver Script";);
llWhisper(0, "Enjoy!";);
}
else if(message == "Keep Sealed";)
{
llWhisper(0, "You keep your package unopened... for now.";);
}
}
}