Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

change & CHANGED_LINK puzzle

Susie Chaffe
Registered User
Join date: 13 Mar 2007
Posts: 29
09-09-2008 20:56
I have a little fleet of ferries running around SL's waterways (server updates not withstanding)
When an avatar sits on one of the seats they receive a greeting message and some instructions.
This is fine for one avatar..but as soon as another avatar sits (or stands up), everyone on board receives the greetings message again. This gets annoying after a while.
I have been trying to find a way to send the message only once to each avatar, but the change & CHANGED_LINK event keeps triggering in all links no matter what I try.

I am sure I am missing some simple technique....any suggestions would be greatly appreciated

The script below is used in each of the seats....

CODE

// Ferry seat script
// 1. Sets sit position
// 2. Receives Greeting message from Relay Script (notecard reader)
// 3. Detects Avatar and First Name
// 4. IM's the avatar with Greeting Message and Instructions
// 5. Starts sit or other animation

//============== GLOBAL VARIABLES ==================

// Postion and Rotation of avatar relative to the centre of the object

vector pos = <0.2, -0.75, -0.42>;

vector rot = <90.0,0.0,0.0>;

string greeting;

//============== SCRIPT START ==================

default
{
state_entry()
{
llSitTarget(pos, llEuler2Rot(rot*DEG_TO_RAD));
}

link_message(integer sender_num, integer num, string str, key id)
{
if (num == -6)
{
greeting = str;
}
}

changed(integer change)
{
if (change & CHANGED_LINK)
{
if (llAvatarOnSitTarget() != NULL_KEY)
{
key avatar = llAvatarOnSitTarget();
string Name;
string FirstName;
llRequestPermissions(avatar, PERMISSION_TRIGGER_ANIMATION);
Name = llKey2Name(avatar);
FirstName = llGetSubString(Name, 0, llSubStringIndex(Name, " ") - 1);
llInstantMessage(avatar, "Hello " + FirstName + " " + greeting);
llSleep(1);
llInstantMessage(avatar, "You can stop the boat once in each region by touching the towel");
}
}
}


run_time_permissions(integer perm)
{
string anim = llGetInventoryName(INVENTORY_ANIMATION, 0);
if (anim != "")
{
llStopAnimation("sit");
llStartAnimation(anim);
}
}
}

//============== SCRIPT END ==================

Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
09-09-2008 22:05
Maybe something like this (pared down to the basics for this example):

CODE

state_entry()
{
llSitTarget(pos, llEuler2Rot(rot*DEG_TO_RAD));
}

changed(integer change)
{
if (change & CHANGED_LINK)
{
if (llAvatarOnSitTarget() != NULL_KEY)
{
*** do announcement stuff ***
state occupied;
}
}
}

occupied()
{
}

changed(integer change)
{
if (change & CHANGED_LINK)
{
if (llAvatarOnSitTarget() = NULL_KEY)
{
state default;
}
}
}
_____________________
Designer of sensual, tasteful couple's animations - for residents who take their leisure time seriously. ;)

http://slurl.com/secondlife/Brownlee/203/110/109/

Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
09-09-2008 23:33
Each avatar that sits on an object is added at the end of the linkset. So you just check the prim count of your linkset and if it increased, get the key/name of the last "prim" in your linkset and send the greeting to that one.
Susie Chaffe
Registered User
Join date: 13 Mar 2007
Posts: 29
09-09-2008 23:48
Thank you Anti, that worked perfectly.........I knew there had to be a reasonably simple solution. Guess I had better head over to your store and check out your sits now :)
Susie Chaffe
Registered User
Join date: 13 Mar 2007
Posts: 29
09-09-2008 23:59
Thanks Squirrel....now I really am feeling dumb. I am using exactly that technique to de-rez the other type of rezzable ferry units.......didn't think of using it for sending the messages.

Both techniques work so I will see which fits in best as the script package develops

Thanks again to both of you for solving my little puzzle.