Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Multi Poseball Sync

Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
11-12-2008 07:09
HIyas Everyone,

I have looked thru the wiki and past posts but haven't found a solution to a problem I would like to solve.

I have 8 linked objects in which the 7 children are poseballs. each containing the sync script I have been working on.

When someone "sits"s on a poseball a "sync" occurs. This will happen until all the poseballs are occupied. This works fine. The problem I'm having is that when an avatar "unsits" from a poseball (while any of the others are occupied), I get a "sync" event for the remaining avatars. There's a loop somewheres I cant' figure out. It seems I get the "sync" event even when avatar=NULL_KEY. All help will be greatly appreciated. :-)

Here's what I have for the change event:

changed(integer change)
{
if(change & CHANGED_LINK)
{ key avatar = llAvatarOnSitTarget();
if (avatar!=NULL_KEY)
{
if(llGetPermissionsKey() != avatar)
{ llRequestPermissions(avatar, PERMISSION_TRIGGER_ANIMATION);
}
hide();
llMessageLinked(LINK_SET, TRUE, "sync", llGetKey());
}
else if ((llGetPermissionsKey()!=NULL_KEY) && (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION))
{
show();
stopAnims();
}
}
}

run_time_permissions(integer perm)
{
key avatar = llAvatarOnSitTarget();
if(perm & PERMISSION_TRIGGER_ANIMATION && llKey2Name(avatar) != "" && avatar == llGetPermissionsKey())
{
stopAnims();
llStartAnimation(llList2String(ANIMS,0));
hide();
}
}
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
11-12-2008 12:16
...because the change event is triggered in ALL SCRIPTS.

hth
/esc
_____________________
http://slurl.com/secondlife/Together
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
11-12-2008 12:38
I've tried timers and different states. But it all goes back to requiring that change_link to initiate the "sync". And once that is established, it's going to be there when someone unsits causing a new "sync". I know I have seen it done... haven't I? Still plugging away. :-)
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
11-12-2008 12:38
...so you'll want to keep track of what the LAST value of llAvatarOnSitTarget() was and compare it to the new value to see if someone has really just sat down or if they are STILL sitting.
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
11-12-2008 17:31
a nice easy way to handle it, is to also just change the state. If someone sits on that prim llAvatarOnSitTarget != NULL_KEY for the first time, just change the state and wait for that return to be null key... clean and easy.
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
Finished Product
11-13-2008 05:33
Thanks everyone for the help. I did a little of this and a little of that and everything works great! I'm going to post it here for all to enjoy!

EDIT: This script seems to work fine for individual poseballs as well although it is a little much for that. :-)


// Multiple Linked Poseball Sync

// This script allows the automatic sync of multiple linked poseballs looping the same single animation. Works fine for individual poseballs as well.

// Place a copy of this script inside each poseball in linked set.

// Chat commands:

// /channel sync - Manual Sync of Poseballs
// /channel hide - Hides Poseballs
// /channel show - Shows Poseballs

//// Written by Zena Juran Nov.13th, 2008. No licensing expressed... do what you want with this code. :-)


// ***** Change the Below Values to Suit Your Needs *****

list ANIMS = ["Dance 5"]; // Animation
string BUTTON = "Dance"; // Text of Pie Menu
string TITLE = "Dance"; // Hovering Text
vector ROTATION = <0,0,0>; // Avatar Rotation
vector OFFSET = <0,0,0.1>; // Avatar Position
integer CHANNEL = 1; // Chat Command Channel
integer LISTEN = TRUE; // Toggle Chat Listen
integer listener;

// ***** End of any necessary changes *****

start_listen()
{
llListenRemove(listener);
if (LISTEN==TRUE)
listener=llListen(CHANNEL,"",llDetectedKey(0),"";);
}

show()
{
llSetText(TITLE, <1.0,1.0,1.0> ,1.0);
llSetAlpha(1.0, ALL_SIDES);
}

hide()
{
llSetText("", ZERO_VECTOR, FALSE);
llSetAlpha(0.0, ALL_SIDES);
}

stopAnims()
{
llStopAnimation(llList2Key(ANIMS,0));
}

default
{
state_entry()
{
llSitTarget(OFFSET, llEuler2Rot(ROTATION * DEG_TO_RAD));
llSetSitText(BUTTON);
show();
start_listen();
}

on_rez(integer n)
{
llResetScript();
}

listen( integer channel, string name, key id, string message )
{
if (message=="hide";)
{
hide();
}
else if (message=="show";)
{
show();
}
}

timer()
{
stopAnims();
llSleep(1.0);
llStartAnimation(llList2String(ANIMS,0));
llSetTimerEvent(0);
state SAT;
}

changed(integer change)
{
if(change & CHANGED_LINK)
{
key avatar = llAvatarOnSitTarget();
if (llAvatarOnSitTarget()!=NULL_KEY)
{
llRequestPermissions(avatar, PERMISSION_TRIGGER_ANIMATION);
hide();
llMessageLinked( LINK_SET, TRUE, "", avatar);
llSetTimerEvent(0.1);
}
else if ((llGetPermissionsKey()!=NULL_KEY) && (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION))
{
show();
stopAnims();
}
}
}

run_time_permissions(integer perm)
{
key avatar = llAvatarOnSitTarget();
if(perm & PERMISSION_TRIGGER_ANIMATION)
{
stopAnims();
llStartAnimation(llList2String(ANIMS,0));
hide();
}
}
}

state SAT
{
state_entry()
{
start_listen();
}

link_message(integer sender_num, integer num, string str, key id)
{
if (num)
{
llSetTimerEvent(0.1);
}
}

listen( integer channel, string name, key id, string message )
{
if (message == "sync";)
{
llSetTimerEvent(0.1);
}

if (message=="hide";)
{
hide();
}

else if (message=="show";)
{
show();
}
}

timer()
{
hide();
stopAnims();
llSleep(1.0);
llStartAnimation(llList2String(ANIMS,0));
llSetTimerEvent(0);
}

changed(integer change)
{
if(change & CHANGED_LINK)
{
if(llAvatarOnSitTarget()==NULL_KEY)
{
show();
stopAnims();
llResetScript();
}
}

}
}