Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llInstantMessage in linked prims problem

Brett Bjornson
Registered User
Join date: 8 Nov 2005
Posts: 25
10-03-2007 07:37
I have a seating circle - several prims arranged in a circle, each prim with it's own seating script. All prims are linked. When I use llInstantMessage in a script in the seat for the first avatar that sits, no problem. But when a second avatar sits on a different seat, the first avatar also sees the messages sent to the second avatar by llInstantMessage. Not so good.

At first I thought this was because the script in each seat is the same, and I used key agent to ID the user. So I changed agent to agent1 in one seat - same result.

Then I unlinked all and tried it, and it works as it should. I'd like to leave things linked together in possible. Any suggestions? Thanks!
Atashi Toshihiko
Frequently Befuddled
Join date: 7 Dec 2006
Posts: 1,423
10-03-2007 08:29
When someone sits down, it triggers a changed event in each and every prim in the linkset. So every prim sees the CHANGED_LINK and I suspect that within the changed event you are testing to see if there is an avatar on the sit target.

So what will happen is the first person sits down and there is a message. Then the second person sits down and now both people get a message. Then the third one sits down and now all three get a message.

I have run into this myself with a 6-person vehicle :-) Every time someone sits (or stands up) every prim sees the change event, every prim checks to see if it has a passenger, and every prim that has a passenger triggers a message.

One way to solve it is to have one 'master' script that controls the sending of messages. Each seat then just uses a link message to send the UUID of the avatar on the sit target. So it's either sending a real UUID or a null key, depending on if someone has sat down or stood up. Then the 'master script' can use a list to record the UUIDs on each seat, and you can script it to only message new UUIDs and not re-send messages to UUIDs that are already on the list.

Edited to add: Another way would be to have each seat script just toggle a true/false integer that says whether or not it's already sent a message. Have it toggle to true when the avatar on the sit target is not null_key and a message is sent, and have it reset to false when the uuid is null_key.

-Atashi
_____________________
Visit Atashi's Art and Oddities Store and the Waikiti Motor Works at beautiful Waikiti.
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
10-03-2007 08:31
Might help if you provided a snippet of the script. I can't see how a script in chair 2 could know the key of the avatar sitting on chair 1 except by link message or (and it's just a wild guess) checking the key of a link number. With llAvatarAtSitTarget you know that the key returned is that of the avatar sitting on the prim (as long as you defined a sit target).

EDIT: Ah, I think Atashi has it. The 1st chair is just noticing the changed link event and responding. Another method from Atashi's would be to store the UUID of the avatar when you first detect them, next time a changed link event is triggered you check to see if the llAvatarAtSitTarget is equal to your current UUID in which case do nothing, if it's empty then set your stored UUID to empty. Only when your stored UUID is empty and there is a new UUID for the llAvatarAtSitTarget do you send the message.
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum
Brett Bjornson
Registered User
Join date: 8 Nov 2005
Posts: 25
Here is the script
10-03-2007 11:47
Still not working. I added an integer sendMessage as suggested.

Sorry for the formatting. I forget the tags to format code here.


//This script modified from a script by AngryBeth Shortbread. Many Thanks!

key agent; //Identify the agent.

vector pos = <-0.25,0,0.8>; //adjust the position to fit object -must be
//nonzero in at least one direction or script will not work!
rotation rot = <0,0,0,1>; //adjust rotation (1 in any vector gives 90 deg)

integer sendMessage = 0;

default
{
state_entry()
{
llSitTarget(pos, rot); //Place the agent on the seat at the correct position and rotation.
}

changed(integer change) //The agent did something.
{
if (change & CHANGED_LINK)
{
agent = llAvatarOnSitTarget(); //Is the agent sitting?
{
if (agent != NULL_KEY) //Yes, get permissions to do things.
{
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
}
else //No, reset all to normal.
{
llReleaseControls();
llResetScript();
}
}
}
}

run_time_permissions(integer perm)
{

if(perm) //We got permissions to animate the agent.
{
llStopAnimation("sit";); //Cancel default sit position
llStartAnimation("sit_ground";); //And substitute this one instead.
}
else //We do not or no longer have permissions to animate the agent.
{
sendMessage = 0;
llUnSit(agent); //Make the agent stand up.
}

if (perm & PERMISSION_TAKE_CONTROLS) //Reassign keys to do what we want. Inform the agent.
{
llTakeControls(CONTROL_UP | CONTROL_DOWN | CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT, TRUE, FALSE);
if (sendMessage == 0)
{
llInstantMessage(agent, "Press the fly up (PAGE UP) key to raise your hand.";);
llInstantMessage(agent, "Press the fly down (PAGE DOWN) key to lower your hand.";);
sendMessage = 1;
}
}
}

control(key id, integer held, integer change)
{
if (change & CONTROL_UP) //Hand was raised.
{
llStartAnimation("raisehand";);
llSetTimerEvent(30.0); //After 30 seconds, lower the hand automatically. See the timer() function below.
}

if (change & CONTROL_DOWN) //Hand was lowered.
{
llSetTimerEvent(0.0);
llStopAnimation("raisehand";);
llStopAnimation("lowerhand";);
}

}

timer() //Teacher is NOT paying attention. Cancel the raised hand.
{
llSetTimerEvent(0.0);
llStopAnimation("raisehand";);
}

}
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
10-04-2007 02:29
From: Brett Bjornson
Still not working. I added an integer sendMessage as suggested.

Sorry for the formatting. I forget the tags to format code here.

Don't worry, the code tags (which are [ php ] [ /php ]) don't work as the formatting has been turned off. :mad:

From: nand Nerd's modification

//This script modified from a script by AngryBeth Shortbread. Many Thanks!
// Slight tweak by nand Nerd

key agent; //Identify the agent.
key last_agent; //Used to store the agent's key between calls.

vector pos = <-0.25,0,0.8>; //adjust the position to fit object -must be
//nonzero in at least one direction or script will not work!
rotation rot = <0,0,0,1>; //adjust rotation (1 in any vector gives 90 deg)

default
{
state_entry()
{
llSitTarget(pos, rot); //Place the agent on the seat at the correct position and rotation.
}

changed(integer change) //The agent did something.
{
if (change & CHANGED_LINK)
{
agent = llAvatarOnSitTarget(); //Is a new agent sitting?
{
if ((agent != NULL_KEY) && (agent != last_agent)) //Yes, get permissions to do things.
{
last_agent = agent; //store this for the next changed event.
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
}
else if ((agent == NULL_KEY) && (last_agent != NULL_KEY))//No, last_agent has stood up, reset all to normal.
{
last_agent = NULL_KEY; // empty the variable, kinda useless since we reset the script but included for completeness
llReleaseControls();
llResetScript();
}
}
}
}

run_time_permissions(integer perm)
{

if(perm) //We got permissions to animate the agent.
{
llStopAnimation("sit";); //Cancel default sit position
llStartAnimation("sit_ground";); //And substitute this one instead.
}
else //We do not or no longer have permissions to animate the agent.
{
sendMessage = 0;
llUnSit(agent); //Make the agent stand up.
}

if (perm & PERMISSION_TAKE_CONTROLS) //Reassign keys to do what we want. Inform the agent.
{
llTakeControls(CONTROL_UP | CONTROL_DOWN | CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT, TRUE, FALSE);
llInstantMessage(agent, "Press the fly up (PAGE UP) key to raise your hand.";);
llInstantMessage(agent, "Press the fly down (PAGE DOWN) key to lower your hand.";);
}
}

control(key id, integer held, integer change)
{
if (change & CONTROL_UP) //Hand was raised.
{
llStartAnimation("raisehand";);
llSetTimerEvent(30.0); //After 30 seconds, lower the hand automatically. See the timer() function below.
}

if (change & CONTROL_DOWN) //Hand was lowered.
{
llSetTimerEvent(0.0);
llStopAnimation("raisehand";);
llStopAnimation("lowerhand";);
}

}

timer() //Teacher is NOT paying attention. Cancel the raised hand.
{
llSetTimerEvent(0.0);
llStopAnimation("raisehand";);
}

}
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum