Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dance script error

Haden Cazalet
Registered User
Join date: 26 May 2008
Posts: 2
09-26-2009 14:32
I have this Dance script which holds upto 50+ Dances. when me and my wife are on it and chose dances, every now and again when one of us changes a dance it gives an error which say unable to find specified agen to request permisions and sometimes it changes the other persons dance instead of your own. if anyone could help me pinpoint the error in the code and point me in the rught direction on how to correct this, would be mosst greatfull.

CODE


list ANIMS = [];
list ANIMS2 = [];
list BUFFER = [];
key chave;
integer listener;
integer i;
integer count = 0;
integer ini = 0;
integer final = 0;

Dialog(key chave, list BUFF)
{
listener = llListen(777, "", NULL_KEY, "");
if ((chave == llGetPermissionsKey()) && (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION))
llDialog(chave, "Select the animation you want to play: ", BUFF, 777);
else
llRequestPermissions(llDetectedKey(0), PERMISSION_TRIGGER_ANIMATION);
}

default
{
on_rez(integer num)
{
llResetScript();
}

state_entry()
{
for (i = 0; i < llGetInventoryNumber(INVENTORY_ANIMATION); i++)
ANIMS += [llGetInventoryName(INVENTORY_ANIMATION, i)];
}

touch_start(integer total_number)
{
chave = llDetectedKey(0);
ini = 0;
final = 8;
BUFFER = ["STOP"] + ["MORE..."] + ["...BACK"] + llList2List(ANIMS, ini, final);
Dialog(chave, BUFFER);
}

run_time_permissions(integer perm)
{
if ((chave == llGetPermissionsKey()) && (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION))
{
ini = 0;
final = 8;
BUFFER = ["STOP"] + ["MORE..."] + ["...BACK"] + llList2List(ANIMS, ini, final);
Dialog(chave, BUFFER);
}
}


listen(integer channel, string name, key id, string message)
{
if (channel == 777)
{
llListenRemove(listener);
if (message == "MORE...")
{
if (final < llGetInventoryNumber(INVENTORY_ANIMATION) - 1)
{
ini += 9;
final += 9;
}
BUFFER = ["STOP"] + ["MORE..."] + ["...BACK"] + llList2List(ANIMS, ini, final);
Dialog(chave, BUFFER);
}
else if (message == "...BACK")
{
if (final >= llGetInventoryNumber(INVENTORY_ANIMATION) - 1)
{
ini -= 9;
final -= 9;
}
BUFFER = ["STOP"] + ["MORE..."] + ["...BACK"] + llList2List(ANIMS, ini, final);
Dialog(chave, BUFFER);
}
else if (message == "STOP")
{
list anims = llGetAnimationList(llGetPermissionsKey()); // get list of animations
integer len = llGetListLength(anims);
for (i = 0; i < len; ++i)
{
llStopAnimation(llList2Key(anims, i));
llSleep(0.2);
}
llStartAnimation("stand");
Dialog(id, BUFFER);
}
else
{
list anims = llGetAnimationList(llGetPermissionsKey()); // get list of animations
integer len = llGetListLength(anims);
for (i = 0; i < len; ++i)
{
llStopAnimation(llList2Key(anims, i));
llSleep(0.2);
}
llStartAnimation("stand");
llStartAnimation(message);
Dialog(id, BUFFER);
}
}
}

}

CODE
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
09-26-2009 15:15
Are you trying to dance more people on one script?
You can't do that, One script can only handle one animation permission. That is why chimeras and dance balls have a number of slots where each slot is a single script. The scripts are identical for all slots, but there is a master script to delegate the dancers to the slots.
_____________________
From Studio Dora
Haden Cazalet
Registered User
Join date: 26 May 2008
Posts: 2
09-26-2009 15:40
well actually ive just found that i have the same script in another dance machine i bought at least a year ago and it only has the one script init and i know for a fact it doesnt error and has had many people on it at the same time. the script i posted is the same script but is giving the error i stated in my opening comments. i am just trying to see if anyone can identify the error for me. I'm learning to script but this is just a little advanced for me to spot the error.
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
09-27-2009 03:27
Until someone wiser than me comes along I must insist :)
You probably can start more dancers on your script, but the minute they change dance or stop dancing you are in trouble.

When you request animation permission(llRequestPermissions) you associate a key with the permission.
When the permission is granted(run_time_permissions) no key is associated.
When you check for permission(llGetPermissions()) no key is associated.
Neither llStopAnimation nor llStartAnimation has any key associated.

The conclusion is, that one script can keep track of one dancer only.

When the script check permission and start or stop animations it will be for the last dancer who gave it animation permission.

Take a look at a real approach:
http://www.lslwiki.net/lslwiki/wakka.php?wakka=LibraryDanceMachine
It is the widespread "Solop Machine". Not the prettiest code but it works:)
_____________________
From Studio Dora
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
09-27-2009 14:04
One problem is a line in your custom Dialog() function: llRequestPermissions()

llDetectedKey() only works in events that support detects (touch, sensor, collision). So replace that llDetectedKey() with your chave.... but that brings up a whole new problem. You have both a globally declared "chave" and a locally declared "chave". You need the global chave for use within the permissions event... so remove or rename the other.

The more I look at that script, the more potential I see for problems. For the reason Dora points out, it's not the best solution for handling multiple dancers. For starters, each time a different user wants to change animations, they'll have to approve the "animate avatar" request. That could get annoying. Also, if a person has clicked to initiate the dialog... then while they're reading the dialog, another user clicks... then the global key "chave" will switch to the second user. At that point, the first user could choose an animation from the dialog, and have the llStop/StartAnimation functions fail because they've lost permissions.

I suppose that when script limits are in place, something like this could be a viable alternative. So, if you must go this route, you have options... you could build a list of all active dancers, then request permissions as needed. Also, under listen, check to see if "id" equals "chave". If it's not equal, then someone else has initiated a dialog and maybe an IM could inform the first person to try again.

(After chopping this post into bits until it would actually accept, I found that the word spelled S-E-L-E-C-T is off-limits. Used "choose" instead).
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
09-27-2009 14:38
From: DoteDote Edison
(After chopping this post into bits until it would actually accept, I found that the word spelled S-E-L-E-C-T is off-limits. Used "choose" instead).

Actually, it's not the word "select" that's the problem. You can use it. If you do, though, you have to be very careful to avoid using the word F-R-O-M afterwards. Unless you know all the right incantations, spells only appear to work in these forums. :rolleyes:

Incidentally, has anyone else noticed that it's OK to use a "<" symbol without a space after it now, as in "<0,0,1.5>"? Go figure.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at