Jump to content

Arm wrestling animation LSL script: animation won't play properly


arnellou
 Share

You are about to reply to a thread that has been inactive for 456 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I'm working on an LSL script to animate an arm for an arm wrestling animation in Second Life. My goal is to make the arm animate to a certain direction when I press the 'W / S' or 'UP ARROW / DOWN ARROW' key. The idea is that there's an integer range where 0 has the starting animation pose, 1 - 10 the arm goes to the right direction, and -1 to -10 the arm goes to the left direction.

The script seems to work fine the first time I run it, but when I try to go back and forth, the animation stops playing.

Any ideas on what might be causing the animation to stop playing when I go back and forth? Any help would be greatly appreciated! Thanks in advance."

vector gPosition = <-0.60, 0.00, -0.5>;
vector gRotation = <0.0, 0.0, 0.0>;  // in degrees

// range
integer MID = 0;
integer MIN = -10;
integer MAX = 10;

// for hover text
vector COLOR_WHITE = <1.000, 1.000, 1.000>;
float  OPAQUE      = 1.0;

updateValue()
{
    llSetText((string)MID, COLOR_WHITE, OPAQUE);
}

declareGameWinner(string team)
{
    llSay(0, team + " WINS"); 
    MID = 0;
    llStopAnimation("5");
}

// function to trigger animation pose based on int value
// all these animation pose have priority 4 set
adjustArm()
{
                if(MID == 0)
                {
                    llStartAnimation("0");  
                }
                if(MID == -1 || MID == -2)
                {
                    llStartAnimation("0");
                    llStartAnimation("-1");                 
                }
                if(MID == -3 ||  MID == -4)
                {
                    llStartAnimation("-1");
                    llStartAnimation("-2");
                }
                if(MID == -5 || MID == -6)
                {
                    llStartAnimation("-2");
                    llStartAnimation("-3");
                }
                if(MID == -7 || MID == -8)
                {
                    llStartAnimation("-3");
                    llStartAnimation("-4");
                }
                if(MID == -9 || MID == -10)
                {
                    llStartAnimation("-4");
                    llStartAnimation("-5");
                }
                
                // postive
                if(MID == 1 || MID == 2)
                {
                    llStartAnimation("1");                 
                }
                if(MID == 3 ||  MID == 4)
                {
                    llStartAnimation("2");
                }
                if(MID == 5 || MID == 6)
                {
                    llStartAnimation("3");
                }
                if(MID == 7 || MID == 8)
                {
                    llStartAnimation("4");
                }
                if(MID == 9 || MID == 10)
                {
                    llStartAnimation("5");
                }    
}

default
{
    
     touch(integer num_detected)
     {
        MID = 0;
        updateValue();
        llSay(0, "Restart Success!");
     }
    
    on_rez (integer start_param)
    {
        llResetScript();
    }
    
    state_entry()
    {
        llSitTarget (gPosition, llEuler2Rot (gRotation * DEG_TO_RAD));
    }
    
// for sit animation
    changed(integer change)
    {
        if (change & CHANGED_LINK)
        { 
            key av = llAvatarOnSitTarget();
            if (av) 
            {
                llSay(0, av);
                llRequestPermissions(av,  PERMISSION_TAKE_CONTROLS |  PERMISSION_TRIGGER_ANIMATION);
                llStartAnimation("0");
            }else{
                llReleaseControls();
            }
        }
    }
    
// get avatar permissions for controls and animation
    run_time_permissions(integer perms)
    {
        if(perms && PERMISSION_TRIGGER_ANIMATION && PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls( CONTROL_FWD | CONTROL_BACK, TRUE, FALSE );
        }
    }
    
// this is where we control the arm base on the value
// the adjustArm function is invoked to trigger the animations pose
    control(key id, integer level, integer edge)
    {
        integer start = level & edge;
        integer end = ~level & edge;
        integer held = level & ~edge;
        integer untouched = ~(level | edge);
        
        if (start & CONTROL_FWD){
                MID++;
                
                adjustArm();
                updateValue();
                
        }
    
        else if (start & CONTROL_BACK){
                MID--;
                
                adjustArm();
                updateValue();
                
        }
    }
}

 

Link to comment
Share on other sites

I'm reading your post on a mobile phone,  which doesn't make it easy,  bit a few things catch my eye. Your AdjustArm function has a stack of "if" condition statements that really ought to be "if else", for example, and it starts the animation in each of those condition blocks but never stops it. 

The run_time_permissions event also has a logical error. 

if(perms && PERMISSION_TRIGGER_ANIMATION && PERMISSION_TAKE_CONTROLS) 

should be

if(perms & PERMISSION_TRIGGER_ANIMATION ] PERMISSION_TAKE_CONTROLS) 

(Drat! I can't type a bitwise OR symbol on this phone)

Fixing those things won't necessarily solve your problem, but they're a start. 

  • Like 1
  • Thanks 2
Link to comment
Share on other sites

You probably also want to set a maximum and minimum value for MID. Only add to MID if <=10, and only subtract from MID if >=-10:

 

        if (start & CONTROL_FWD){
                MID++;
                
                adjustArm();
                updateValue();
                
        }
    
        else if (start & CONTROL_BACK){
                MID--;
                
                adjustArm();
                updateValue();
                
        }

Otherwise, you could get values of 100 or -100, etc. which your code in adjustArm() does not handle.

One way to figure this part out is to add a debug statement in the adjustArm() function, use llSay() to show the current value whenever you change it.

  • Thanks 1
Link to comment
Share on other sites

2 hours ago, Rolig Loon said:

(Drat! I can't type a bitwise OR symbol on this phone)

On android, there's a wonderful keyboard app called "unexpected keyboard" that can type pipes and other fancy symbols easily.

As for the script, in situations where exactly one animation is supposed to play, it's usually best to just have a global variable set to the running animation, so you can

run_time_permissions(...)
{   if(perms&PERMISION_TRIGGER_ANIMATION)
    {   if(gAnimOld) llStopAnimation(gAnimOld);
        if(gAnimNew)
        {	llStartAnimation(gAnimNew);
            gAnimOld=gAnimNew;
            gAnimNew="";
        }
    }
}

or so. (pro-tip: set the old animation to "sit" to stop the default sitting animation) setting a global variable to the anim you want to play and requesting permissions every time, stops your script from complaining if a sitter uses "reset skeleton and animations".

  • Thanks 2
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 456 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...