Jump to content
Sign in to follow this  
Allison Lynagh

Sooooo close!

Recommended Posts

So, I've managed to hobble together a few codes from various scripts and gotten what I want.. almost. This is a dancer and sound player (A single song with animations that cycle sequentially according to a list). But I've somewhere failed, as the sound cycle is linked to the animation cycle. I kinda need the sound timer event and the animation timer event to be two seperate things so I can have the animation cycle at increments longer than 10 seconds. Any help would be superbly appreciated.

I've determined the line of scripting that needs help (directly below) but I'm not exactly sure how to have 2 timer events triggered at the same time. 

    timer()
    {
     ++gDance;
       
         if(ON == 1){llSetTimerEvent(SoundLength); ON = 2;}
        llStopAnimation(Allison);
        integer i = gDance %llGetListLength(dances);
        Allison = llList2String(dances,i);
        llStartAnimation(Allison);
        llPlaySound((string)(++SoundClipNumber),1.0);
        if(SoundClipNumber == MaxSoundClips){llSetTimerEvent(LastSoundLength); ON = 1; SoundClipNumber = 0;}
        llPreloadSound((string)(SoundClipNumber+1));
        
    }

 

 

integer ON = 0;                    //STATE OF SCRIPT
integer MaxSoundClips = 18;         //AMOUNT OF SONG CLIPS, NAME THEM 1,2,3,4,ETC 
integer SoundLength = 10;           //FIRST SERIES OF SOUND LENGTHS
integer LastSoundLength = 2;       //INCASE LAST SOUND CLIP IS SHORTER
integer SoundClipNumber = 0;       //FOR SOUND LOOP
integer gDance;
list dances = [
 "dance1", 
 "dance2",  
 "dance3"  
 ];                     //LIST DANCES HERE, "Name of Dance", (no comma after last dance
string Allison;

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

    
default
{
    state_entry()
    {
        llListen(0, "", "", "");
    }
    
    attach(key id)
    {
        if(id)
        {
            llOwnerSay(" Commands 'on' or 'off'");
            llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
        }
        else ResetToDefault();
    }


    timer()
    {
     ++gDance;
       
         if(ON == 1){llSetTimerEvent(SoundLength); ON = 2;}
        llStopAnimation(Allison);
        integer i = gDance %llGetListLength(dances);
        Allison = llList2String(dances,i);
        llStartAnimation(Allison);
        llPlaySound((string)(++SoundClipNumber),1.0);
        if(SoundClipNumber == MaxSoundClips){llSetTimerEvent(LastSoundLength); 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;
            Allison = "sit"; //DEFAULT STARTING ANIM, CHANGE IF YOU LIKE
            llStartAnimation(Allison);
            llSetTimerEvent(0.5); //THIS SETS TIME BEFORE THE DANCER KICKS IN
        }
        else if(message == "off"){ResetToDefault();}
    }
}

 

Share this post


Link to post
Share on other sites

You can have a timer event do more than one thing though.

They just won't happen at exactly the same tame. 

I've seen SL take a LONG time to load sounds initially, so playing sounds and sync with animation can be a real problem.  The first / second / third time through, the anim may play with no sound.

Share this post


Link to post
Share on other sites

A 1 second timer in combination with a counter might be what you need.
Like this:

integer seconds;default{    state_entry(){        llSetTimerEvent(1.0);    }        timer(){        ++seconds;        if (seconds == 5){            // do something after 5 seconds        }        if (seconds == 7){           // do something after 7 seconds        }         seconds = 0;    }}

 

Share this post


Link to post
Share on other sites


Allison Lynagh wrote:

So, I've managed to hobble together a few codes from various scripts and gotten what I want.. almost. This is a dancer and sound player (A single song with animations that cycle sequentially according to a list). But I've somewhere failed, as the sound cycle is linked to the animation cycle. I kinda need the sound timer event and the animation timer event to be two seperate things so I can have the animation cycle at increments longer than 10 seconds. Any help would be superbly appreciated.

I've determined the line of scripting that needs help (directly below) but I'm not exactly sure how to have 2 timer events triggered at the same time. 
    timer()    {     ++gDance;                if(ON == 1){llSetTimerEvent(SoundLength); ON = 2;}        llStopAnimation(Allison);        integer i = gDance %llGetListLength(dances);        Allison = llList2String(dances,i);        llStartAnimation(Allison);        llPlaySound((string)(++SoundClipNumber),1.0);        if(SoundClipNumber == MaxSoundClips){llSetTimerEvent(LastSoundLength); ON = 1; SoundClipNumber = 0;}        llPreloadSound((string)(SoundClipNumber+1));            }

 

 
integer ON = 0;                    //STATE OF SCRIPTinteger MaxSoundClips = 18;         //AMOUNT OF SONG CLIPS, NAME THEM 1,2,3,4,ETC integer SoundLength = 10;           //FIRST SERIES OF SOUND LENGTHSinteger LastSoundLength = 2;       //INCASE LAST SOUND CLIP IS SHORTERinteger SoundClipNumber = 0;       //FOR SOUND LOOPinteger gDance;list dances = [ "dance1",  "dance2",   "dance3"   ];                     //LIST DANCES HERE, "Name of Dance", (no comma after last dancestring Allison;ResetToDefault(){    llStopSound();    llSetTimerEvent(0.00);    llStopAnimation(Allison);    ON = 0;    SoundClipNumber = 0;}    default{    state_entry()    {        llListen(0, "", "", "");    }        attach(key id)    {        if(id)        {            llOwnerSay(" Commands 'on' or 'off'");            llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);        }        else ResetToDefault();    }    timer()    {     ++gDance;                if(ON == 1){llSetTimerEvent(SoundLength); ON = 2;}        llStopAnimation(Allison);        integer i = gDance %llGetListLength(dances);        Allison = llList2String(dances,i);        llStartAnimation(Allison);        llPlaySound((string)(++SoundClipNumber),1.0);        if(SoundClipNumber == MaxSoundClips){llSetTimerEvent(LastSoundLength); 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;            Allison = "sit"; //DEFAULT STARTING ANIM, CHANGE IF YOU LIKE            llStartAnimation(Allison);            llSetTimerEvent(0.5); //THIS SETS TIME BEFORE THE DANCER KICKS IN        }        else if(message == "off"){ResetToDefault();}    }}

 

Deja vu code- http://community.secondlife.com/t5/LSL-Scripting/Need-script/m-p/1964773#M16753

[Edit to point more directly to the script I recognized.]

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

×
×
  • Create New...