Jump to content

Making a Animation loop script toggle.


Xenon Engineer
 Share

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

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

Recommended Posts

So I'm pretty bad at the whole scripting thing and just usually fit existing scripts to do what I need for personal use.

Unfortunately I ran into a stump when I'm getting tired of taking an object off to stop an animation.

I was wondering if someone could help make a script with the same function or repurpose this existing one to have a toggle on touch. I've tried different ways but with my limited knowledge I couldn't quite make it turn on and off.

Here it is the way it was.

default
{ 
    state_entry() {
        llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
    }
    on_rez(integer start_param) {
        llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
    }
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            llStopAnimation("Animation");
            llSetTimerEvent(0.05);
        }
    }
    timer() {
        llSetTimerEvent(0);
        llStartAnimation("Animation");
        llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
    }
}

 Any help to make this happen would be greatly appreciated as it'd help very much as it's for personal use and it would just make things way easier.

I want it to stay looping ontop of certain animations like AOs and such.

 

Link to comment
Share on other sites

That's one wierd script.  All you really need to do is take something like the first example script in the LSL wiki at http://wiki.secondlife.com/wiki/LlStartAnimation and turn the animation ON/OFF with a simple touch toggle -- like a light switch -- instead of using a timer event.  Declare a global integer (gON) to use as the toggle, turn it on or off in the touch_start event, and use it in the run_time_permissions event to either llStartAnimation or llStopAnimation.  It's a good first scripting exercise.

Link to comment
Share on other sites

So I have this, it works fine, I just can't get it to have an off function. Maybe I don't know enough but adding "else" just causes syntax errors.

integer on_off;default{    touch_start(integer detected)    {        llRequestPermissions(llDetectedKey(0), PERMISSION_TRIGGER_ANIMATION);    }    run_time_permissions(integer perm)    {        on_off = !on_off;                if (on_off ==TRUE)        {            llStopAnimation("hip1");            llSetTimerEvent(0.02);        }    }    timer()    {        llSetTimerEvent(0.1);        llStartAnimation("hip1");        llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);    }}

 No idea how to make it have a stop function after that.

I need the timer from my knowledge to constantly loop the animation, to constantly keep it as the top animation, you know when you start walking it stops having priority.

This helps solve that problem for say, holding something.

Link to comment
Share on other sites

Not a bad start.  So, a few things:

1. The touch_start event is where you have to turn the switch on and off.  Anything after that is going to react to the value that is set there.

2.You only need to request permissions one time.  After that, you can bypass the run_time_permissions event so that you don't keep popping the permission dialog box up all the time.

HOWEVER ....

3. I didn't understand why you needed the timer from your first post, but I agree that you do need it.  That makes life a little more difficult because it means you need to switch the timer on and off as well as the animation.  Since you'll only use the run_time_permissions event one time, the touch_start event will have to do all the switching after that.  The resulting script will have a few more branches than I thought you'd need at first.

Take a look at this and see why it works:

integer on_off;default{    touch_start(integer detected)    {        on_off = !on_off;        if(!(llGetPermissions() & PERMISSION_TRIGGER_ANIMATION))        {            llRequestPermissions(llDetectedKey(0), PERMISSION_TRIGGER_ANIMATION);        }        else        {            if (on_off)            {                llStartAnimation("hip1");                llSetTimerEvent(0.1);            }            else            {                llStopAnimation("hip1");                llSetTimerEvent(0.0);            }        }            }    run_time_permissions(integer perm)    {        if (perm & PERMISSION_TRIGGER_ANIMATION)        {            if (on_off)            {                llStartAnimation("hip1");                llSetTimerEvent(0.1);            }            else            {                llStopAnimation("hip1");                llSetTimerEvent(0.0);            }        }    }    timer()    {        llStartAnimation("hip1");    }}

 

 This could be written in a more compact way, but I left it wide open  so you could follow the flow. Please don't just copy it without poking at it to see why it works.

You may want to ask yourself why it necessary to run the timer as fast as you were.  I slowed it down, but it's still racing.  A fast timer holds the servers' attention and contributes to lag in the region.  That's one reason why avatars wearing messy AOs make a region so laggy.  Unlesss there's a really good reason, avoid running timers any faster than you need to, and provide a way to turn them OFF when they aren't needed.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3451 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...