Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

I cant get the anims to change back

amiz Georgette
Registered User
Join date: 8 Jul 2008
Posts: 22
07-24-2009 09:51
I have this script and two anims Forward and Stall.
I can click on Forward and it works and the Stall works but If i want to go forward again the anim wont start. This is on an a attached prim doesn that make a diffrence?




list animlist = ["Forward","stall","Stop"];
//put animation names here instead of bow clap sit, dont delete stop
integer channel = 81; //change the number
string anim;
integer listenhandle;

playanim(key av)
{
integer index = llGetListLength(animlist);
list animsplaying = llGetAnimationList(av);
while(index--)
{
string animtest = llList2String(animlist,index);
if(llListFindList(animsplaying,[animtest]) != -1) llStopAnimation(animtest);
//stop playing anims
llStartAnimation("stand";);//This line might be unnecessary
//but I had some weird results ending the animations, when I tested the script.
//the line insures the avatar will stand normally after ending the anims.
}
if(anim != "stop";) llStartAnimation(anim);
}

integer reqperm( key id )
{
if( (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) && (llGetPermissionsKey() == id) )
//if we have permissions to animate play animation
{
return TRUE;
}
else
{
llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
//we dont yet have permission to animate, so we ask for it
//this raises the run_time_permission event below
return FALSE;
}
}

default
{
touch_start(integer total_number)
{
key av = llDetectedKey(0);
listenhandle = llListen(channel, "", av, "";);
llDialog(av, "choose animation", animlist, channel);
}
run_time_permissions(integer perm)
{
if(perm & PERMISSION_TRIGGER_ANIMATION)
{
playanim(llGetPermissionsKey());//we have been granted permission, so we play anim
}
}
listen(integer channel, string name, key av, string message)
{
llListenRemove(listenhandle); //remove the listener to decrese server load
anim = message;
if(reqperm( av )) playanim(av);
}
}
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
07-24-2009 10:39
whitespace and indents are your friend (so are php tags, if you can't see the php as a box format check the link in my signature.)

CODE

list animlist = ["Forward","stall","Stop"];
//put animation names here instead of bow clap sit, dont delete stop

integer channel = 81; //change the number
string anim;
integer listenhandle;

playanim(key av)
{
integer index = llGetListLength( animlist );
list animsplaying = llGetAnimationList( av );
while (index--)
{
string animtest = llList2String( animlist, index );
if (llListFindList( animsplaying, [animtest] ) != -1) llStopAnimation( animtest );
//stop playing anims

llStartAnimation( "stand" ); //This line might be unnecessary
//but I had some weird results ending the animations, when I tested the script.
//the line insures the avatar will stand normally after ending the anims.
}

if (anim != "stop") llStartAnimation( anim );
}

integer reqperm( key id )
{
if ((llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) && (llGetPermissionsKey() == id))
//if we have permissions to animate play animation
{
return TRUE;
}
else
{
llRequestPermissions( id, PERMISSION_TRIGGER_ANIMATION );
//we dont yet have permission to animate, so we ask for it
//this raises the run_time_permission event below
return FALSE;
}
}

default
{
touch_start( integer total_number )
{
key av = llDetectedKey( 0 );
listenhandle = llListen( channel, "", av, "" );
llDialog( av, "choose animation", animlist, channel );
}

run_time_permissions( integer perm )
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
playanim( llGetPermissionsKey() );//we have been granted permission, so we play anim
}
}

listen( integer channel, string name, key av, string message )
{
llListenRemove( listenhandle ); //remove the listener to decrese server load
anim = message;
if (reqperm( av )) playanim( av );
}
}

you're stopping all your own animations AND playing the stand before the first call goes through so it shouldn't be a priority issue, I don't see anything wrong codewise

you probably should declare your string and play the stand BEFORE your while loop, and consider a timer on your listen to prevent missed closing on ignored listens
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-24-2009 10:50
Just quickly, I see two things you'll want to take a closer look at, either one of which can create a problem if you don't fix it ....

(a) Your animlist has three elements. The third one is "Stop." You have a test farther down, though, that says if(anim != "stop";) llStartAnimation(anim); Because "stop" != "Stop" this test will always evaluate to FALSE. You'll never get the device to stop by pushing on a Dialog button.

(b) The elements in animlist are numbered 0,1, and 2. ("Forward" is element 0 and "Stop" is element 2.) So, when you start counting down from index = llGetListLength(animlist), the first time you evaluate string animtest = llList2String(animlist,index), you will get a null value. There is no element numbered 3. You need to count from index-1.

Oh, and you'll want to be sure you have matching brackets where you want them. The block that says
CODE

if(llListFindList(animsplaying,[animtest]) != -1) llStopAnimation(animtest);
//stop playing anims
llStartAnimation("stand");//This line might be unnecessary
//but I had some weird results ending the animations, when I tested the script.
//the line insures the avatar will stand normally after ending the anims.
}

has a closed bracket but not an open one. If your script is executing, it's probably behaving oddly because code blocks aren't defined the way you think they are.
ETA: Ah, wait....... I see. That bracket closes a larger block than I thought. Still, you should get in the habit of always enclosing the executable stuff after an if test in brackets, even if it's only one line. That makes the code LOTS easier to read. :)
_____________________
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
Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
07-24-2009 11:03
Are you missing an operator in this statement?

if (reqperm( av )) playanim( av );

I don't know what this statement is supposed to do, since you don't have any statements following the if condition.
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-24-2009 11:28
From: Galena Qi
Are you missing an operator in this statement?

if (reqperm( av )) playanim( av );

I don't know what this statement is supposed to do, since you don't have any statements following the if condition.

It's another if test without bracket..... confusing. It would be much easier to read if it were written

CODE

if (reqperm(av))
{
playanim(av);
}


;)
_____________________
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
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-24-2009 14:41
I think I've got it. Take a look at this part of your script .....

CODE

list animlist = ["Forward","stall","Stop"];

playanim(key av)
{
integer index = llGetListLength(animlist);
list animsplaying = llGetAnimationList(av);
while(--index)
{
string animtest = llList2String(animlist,index);
if(llListFindList(animsplaying,[animtest]) != -1)
{
llStopAnimation(animtest);
}
}
if(anim != "Stop")
{
llStartAnimation(anim);
}
}


animlist is a list of animation names. Therefore, animtest is also an animation name. When you create animsplaying, however, you are generating a list of animation keys (that's the result of llGetAnimationList). The test you use to llStopAnimation(animtest) will always fail, since you will never find animtest in a list of keys. Therefore, animtest will not stop. If anim == animtest the second time you click a Dialog button, then it's still running.

BTW, notice that I changed while(index--) to while(--index) so that it's reading the list elements properly, and I capitalized "Stop" so that your if test should work.

ETA: Oh, yeah... And I also removed llStartAnimation("Stand";), since it's not really necessary if you fix the llStopAnimation problem. ;)
_____________________
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
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
07-24-2009 20:57
actually the original count was good, --index will fail to test the 0 index whereas index-- decremented it into the proper range before it was operated on, while still catching it

there is a slight flaw, in that stop is not a played animation, so really doesn't need to bet tested for, but with a little list-foo you could do

animlist = ["Stop", "Forward", "Stall"];

//-- and later

while (--index)

it should actually fail if you used the stop dialog button... since it tries to call an anim you don't have (because it's trying to play "Stop" due to the mismatched spelling).... but then I can't remember if that failure would cause the script to stop (in which case you wouldn't be able to get another dialog) or it just throws and error (can't find animation "Stop";), or maybe it's revoking premissions (which would seem really weird, and should throw more script errors like PERMISSION_TRIGGER_ANIMATION not set... )
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-25-2009 08:12
Yup. I got the counter wrong. :o

I'm sure the OP's underlying problem, though, is that she's comparing the results of
string animtest = llList2String(animlist,index) with list animsplaying = llGetAnimationList(av). That comparison will always come up FALSE. Unfortunately, the OP can't create her animlist as a list of keys to compare against unless she knows the keys, and she can't get them unless she has full perms on the animations. Too bad. If it had worked, this would have been a clever idea.
_____________________
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
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
07-25-2009 09:12
:: smacks forehead :: doh... yup I forgot that they changed the behavior of the permissions, not the list that gets returned....

incidently there is a way to get the key because of that choice... stop all anims, play the one you want, and then get the animlist.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-25-2009 10:14
From: Void Singer
:: smacks forehead :: doh... yup I forgot that they changed the behavior of the permissions, not the list that gets returned....

incidently there is a way to get the key because of that choice... stop all anims, play the one you want, and then get the animlist.


My turn to say "d'uh" (again). I should have thought of that.
_____________________
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