Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How Do You Pass A key?

Axion Epsilon
Registered User
Join date: 13 Sep 2005
Posts: 2
09-14-2005 16:05
Hi Everyone,
I'm new to SL and am having trouble finding some answers. I've looked through the LSL Wiki and am just not finding what I need.

I want to create a door mat that uses a script to rez on object. (I got this to work)
The new object needs the key of the person who steped on the mat. (no idea how to do this)
The new object follows the person who steped on the mat(I can get this to follow me)

Where should I start? any idea where I should look?

Thanks
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
09-14-2005 16:15
You can only pass an integer to a rezzed object, and it's difficult (if not impossible) to encode a key into an integer. The way I would do this is to open up a listener in the rezzed object, and have the rezzer tell it the key using chat. So...

In the doormat:

CODE

...

integer chatChannel = 98765; // Use any non-zero number, preferably high up

...

llRezObject(.... , chatChannel, ...); // Pass in chatChannel where you pass the integer parameter

...

object_rez(...)
{
// This gets called when the object has been rezzed. Just to be safe and
// protect against lag, sleep a little so the script in the rezzed object
// gets the time to start running and set up its listener, then tell it the key

llSleep(0.5);
llSay(chatChannel, (string)keySavedFromWhenPersonSteppedOnMat);
}


And in the follower/pet thingy:

CODE

integer chatHandle;
key keyForFollowerToUse;

on_rez(integer param)
{
// Param is the chat channel to listen on
chatHandle = llListen(chatChannel, "", NULL_KEY, "");
}

listen(integer channel, string name, key id, string message)
{
// The message that comes in is the key
keyForFollowerToUse = (key)message;

// Reduce lag, kill the listener since you don't need it any more
llListenRemove(chatHandle);
}


Edited for typo
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
09-14-2005 16:41
From: Axion Epsilon
Hi Everyone,
The new object needs the key of the person who steped on the mat. (no idea how to do this)
Thanks

Parent forgot the above question.
You can get the key to the person who stepped on the mat by using llDetectedKey in the collision event of the mat. Save it to a global if you want to share it with other event handlers and functions.

CODE

collision(integer total)
{
//Passing 0 gets the key to the first person that stepped on the mat
gUser=llDetectedKey(0);
//do stuff like llRezObject... what the parent said.
}
Axion Epsilon
Registered User
Join date: 13 Sep 2005
Posts: 2
09-14-2005 19:24
Thanks for the help, I got it working.

I changed the

integer chatChannel = 98765; // Use any non-zero number, preferably high up
to
integer chatChannel = 98765 + llRound(llFrand(500)); // Use any non-zero number, preferably high up

in the collision call so each Ghost would be on a different channel Probly not neccery, but better safe than sorry

p.s.
I figured out the

gUser=llDetectedKey(0);

But glad to know I did it right
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
09-14-2005 21:26
If you have multiple ghosts, that's a good idea.