Jump to content
dayz Short

looping dancer with 2 animations - 1 of wh...its complcated

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

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

Recommended Posts

Hello ūüėɬ†I'm so new to scripting, I haven't even stated¬† one yet.... not quite true but almost. I hope someone can help

what i have...10 sec. length sound clips,2 animations, a standard dancer script that plays one animation and loops perfectly.. 

what i need....to change the script so that it will allow me to take the first animation...A1, and play it for a specific length of time, then step in with A2, and play it for its duration, then step back with A1 same.. then A2....and then loop to begin all again.

I dont know if this is possible. Am i looking to insert an event that  says if sound clip 3 is playing start A2. can i start A1 normally and then stop that animation an d begin A2 - triggered by the sound clip that's playing? and then do it again, and then send it on  its loop to start over?

This is the script

 

integer ON = 0;                    
string animation = "xxx"Name of the Animation
integer Max_Sound_Clips =9//number of Sound Clips    
integer Sound_Length = 10; //sound length 1-10          
integer Last_Sound_Length = 10;       
integer SoundClipNumber = 0;//   
//Dont change anything below

ResetToDefault()
{
    llStopSound();
    llSetTimerEvent(0.00);
    llStopAnimation(animation);
    ON = 0;
    SoundClipNumber = 0;
}

    
default
{
    state_entry()
    {
        llListen(0, "", "", "");
    }
    
    attach(key id)
    {
        if(id)
        {
            llOwnerSay(" To Turn On: On // To Turn Off: OFF");
            llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
        }
        else ResetToDefault();
    }

    timer()
    {
        llPlaySound((string)(++SoundClipNumber),1.0);
        if(ON == 1){llSetTimerEvent(Sound_Length); ON = 2;}
        if(SoundClipNumber == Max_Sound_Clips){llSetTimerEvent(Last_Sound_Length); ON = 1; SoundClipNumber = 0;}
        llPreloadSound((string)(SoundClipNumber+1));
    }
    
    listen(integer channel, string name, key id, string message)
    {
        message = llToLower(message);
        if (ON == 0 && message == "on")
        {
            ON = 1;
            llStartAnimation(animation);
            llSetTimerEvent(0.01);
        }
        else if(message == "off"){ResetToDefault();}
    }
}
 

do i need something like this?

integer AnimCycleTime = 0;
integer CurrAnimCycle = 0;
integer AnimNumber = 0;
integer MaxAnims = 0;
string LastAnim = "";
ResetToDefault()
{
llStopSound();
llSetTimerEvent(0.00);
llStopAnimation(LastAnim);
ON = 0;
SoundClipNumber = 0;
AnimNumber = 0;
}

 

and if so do i need to put in a separate animation  ..erhm...named a1 a2 a3 a4 .. and then name them in the script

 

Would be very appreciated if anybody can point me in the right direction with this¬† and thank you ūüėÉ

 

Share this post


Link to post
Share on other sites

If it is only going to be two animations then yes, name them a1 and a2, and in the timer event, switch between a1 and a2.

You also need to add a run_time_permissions event in which a check is made before stopping and starting animations, since it either isn't in your example script or hasn't been included in the copy and paste. (Many early scripters assumed that attaching an item automatically grants all permissions and didn't bother with such checks).

In the run_time_permissions event, check that trigger animations permission has been granted, and if so, start the first animation, set some variable so that the timer event knows which is the current animation and can switch to the next one, and then start the timer.

(In your example script the timer is being set to trigger one hundred times a second, which is far too fast, set it to 10.0 )

In the timer event, you must first check that you have the avatar permission for triggering animations and if so, stop the current animation, and start the next one, and set the variable so that next time in the timer loop it knows what to stop and what to start.

I suggest you look in the LSL Portal wiki for run_time_permissions event to see some examples, but this is roughly what it will look like for your script

run_time_permissions(integer perms)

{

    if(perms & PERMISSION_TRIGGER_ANIMATION)

    {

        if( thisAnim != "") llStopAnimation(thisAnim);    // if we are already playing an animation stop it first

        else thisAnim = a2;    // at startup set thisAnim = "" so that the permissions doesn't try to stop a non-running animation and prepares to start a1

        if( thisAnim == a1) thisAnim = a2;    // toggle one or the other animations

        else thisAnim = a1;

        llStartAnimation(thisAnim);

    }

}

and this is what you would then have in the timer() event

timer()

{

    llRequestPermissions(wearer, PERMISSION_TRIGGER_ANIMATION);

}

 

and in order to make that work, you need to do three more things:

 

declare a global variable for the wearer and another for the thisAnim string
 

key wearer = NULL_KEY;

string thisAnim = "";

 

and in the attach event, assign the id of the avatar to whom it has attached to the wearer variable

 

wearer = id;

 

 

I also suggest you either change the channel number from 0 to something like -100, or else you alter the listen so that it is listening for the wearer only. Grabbing everything said on channel 0 can be vary laggy.

 

There are simpler or more elegant ways of doing this but they are harder to understand for somebody starting out by tweaking scripts

Edited by Profaitchikenz Haiku
Inserting a clause to forestall persons claiming I should have said use llXYZ instead of what I have suggested

Share this post


Link to post
Share on other sites

If you laid the script out in a format that it is easier to read would make a vast difference. It would also make syntax errors noticable. Have np idea how you can read that without eye strain.

There are two syntax errors here. The stattements have no closure.

string animation = "xxx"Name of the Animation
integer Max_Sound_Clips =9//number of Sound Clips   

Edited by steph Arnott

Share this post


Link to post
Share on other sites

One thing to consider for the future: I've found llSetSoundQueuing() useful to make the timing of starting a new sound somewhat more forgiving. If you start it a bit before it's supposed to play, queuing will force it to wait until the previous sound has completed. Either way, though, none of this is perfectly reliable, depending as it does on timing of sim-viewer messaging. So... I guess test for yourself and pick the more palatable poison.

A more pressing problem may be the need to multiplex two series of asynchronous event intervals, the sound starting and the anim-switching. There's a common trick that uses the heartbeat of no_sensor() events from an impossible-to-detect llSensorRepeat() to trigger one series of events while the timer() events do the others. Or you can slot both series into the one timer() queue and then when an event occurs test which interval(s) must have expired. Neither approach is exactly elegant.

[EDIT: A third approach uses a separate slave script to do a separate event sequence. That's usually wasteful, but it occurs to me that I don't know what a "dancer" really is, so if animations of more than one avatar are involved, you'd probably want separate scripts to hold permissions for each of them anyway, so adding one more for sound might not be worth worrying about.]

Edited by Qie Niangao

Share this post


Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 596 days.

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...