Jump to content

Help me place my timer


kari1sl
 Share

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

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

Recommended Posts

Hi Folks.

I built a HUD that is growing crowded and unmanageable with a button for each animation sequence, so I have been trying to transplant it to a chatable method but placing the timer() seems to give a Syntax Error everwhere I've tried.
Below is the CHAT code...

//CHATFACE FOR 2 v8
list ah =["express_open_mouth", "express_toothsmile", "express_open_mouth", "express_open_mouth", "express_open_mouth", "express_toothsmile", "express_open_mouth", "express_surprise_emote", "express_open_mouth"];
list oh =["express_kiss", "express_open_mouth", "express_kiss", "express_open_mouth", "express_kiss", "express_open_mouth", "express_kiss", "express_open_mouth", "express_kiss"];

integer Handle; integer gCount;integer gON; list anilist; 

default
{
    on_rez(integer start_param)
{
    llResetScript();
}
  state_entry()
//timer()//ERROR : Syntax error
{
                llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
        }
        //        timer()//ERROR : Syntax error
        run_time_permissions(integer perm)
   //timer()//ERROR : Syntax error
             {
            if(PERMISSION_TRIGGER_ANIMATION & perm)
        {
                llOwnerSay(llGetScriptName() + " has PERMISSION_TRIGGER_ANIMATION perms for  "+(string)llGetPermissionsKey());llSetTimerEvent(2);
        }
                //timer()//ERROR : Syntax error
    if (perm == 0)
       // timer()//ERROR : Syntax error
        {
        llOwnerSay(llGetScriptName() + " has NO perms for  "+ (string)llGetPermissionsKey());
        }
          llListen( 0, "", llGetOwner(), "" );  
        }
        //  timer()//ERROR : Syntax error
        listen(integer channel, string name, key id, string message)
       //timer()//ERROR : Syntax error
         {
            llSay(0, message);list input = llParseString2List(message, [" "], []);string gate = llList2String(input, 0); string action = llList2String(input, 1);llSay(0, (string)gate);
        if (gate == "off")
            {
            llListenControl(Handle, FALSE);
            }
            else if (gate == "express"|| gate == "xpress" || gate == "x")
            {
                list input = llParseString2List(message, [" "], []); action =  llList2String(input, 1); llSay(0, (string)action);
            if (action == "ah")
                {
                anilist = llList2List(ah,0,55);
                }
                else if (action == "oh")
                {
                    anilist = llList2List(oh,0,55);
                }
                else
                {
                        llSay (0, "Not a recognized face command. Give permission (again) and try again using one of these ..."); llResetScript();
                }
//timer()//ERROR : Syntax error
                {
                            integer length = llGetListLength(anilist); llSay(0,(string)action + " is " + (string)length + " units long and its sequence is  " + (string)anilist);
                {
                    gON = !gON;gCount = 0; llStartAnimation(llList2String(anilist, 0)); llSetTimerEvent(0.1* gON);
                }
                {
                        gON = TRUE; gCount = 0; llSetTimerEvent(2.0);
                }
timer()//ERROR : This is the "right place but SYNTAX ERRORS!
{
                integer i = ++gCount;
                        {
                    llStopAnimation(llList2String(anilist, i-1));
                }
                        if (i < length)
                    {
                                             llSay(0, (string)i + (string)llList2String(anilist, i)); // say the ani # & name
                    llStartAnimation(llList2String(anilist, i+1));
                        }
}                                                          
                        }
}
                    else
                        {
                        llSay (0, "Not a face command. Give permission (again) and chat an \"x\", or \"xpress\" ot \"express\" to start, and then the command"); llResetScript();
   //timer()//ERROR : Syntax error
                                         }
                    }

}

 


1) tweaked from a touch command to listening,
2) adapted to chose from a library of lists instead of using the single list in its sole button
3) with extra "llSays" added to help me to understand what is going on.
4) I have double lined (//) commented each place I have tried and failed to position the timer() and the position that (I think) most corresponds to the position in the button (where is works) is left withouot "//" in from and with "timer()//ERROR : This is the "right place but SYNTAX ERRORS!!"
... and in the process, really messed up the indentation system (soory).
BTW - without the timer, the i++ loop doesn't loop!
I can post the "touch buttom" (that works) if folks think it might be useful.

Thanks,,,

Link to comment
Share on other sites

There are actually multiple syntax problems here. Below, I'll post a cleaned-up and commented version that at least compiles and starts some animations before it hits a runtime error.  We can work on those errors and extending the script if you get stuck, but I wanted you to have some base from which to begin debugging.

I would stress that formatting is just extremely important. Indenting consistently, and adopting some conventions (such as no more than one statement per line) will make it much easier to read your own code in future, as well as detect syntax problems as you write the code.

Also a note that "{" and "}" serve a very specific purpose in the grammar of languages like LSL: they start and end a block of code, and they must always balance. Variables are scoped to the innermost block in which they're defined.

//CHATFACE FOR 2 v8list ah =["express_open_mouth", "express_toothsmile", "express_open_mouth", "express_open_mouth", "express_open_mouth", "express_toothsmile", "express_open_mouth", "express_surprise_emote", "express_open_mouth"];list oh =["express_kiss", "express_open_mouth", "express_kiss", "express_open_mouth", "express_kiss", "express_open_mouth", "express_kiss", "express_open_mouth", "express_kiss"];integer Handle; integer gCount;integer gON; list anilist; default{    on_rez(integer start_param)    {        llResetScript();    }    state_entry()    {        llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);    }    run_time_permissions(integer perm)    {        if(PERMISSION_TRIGGER_ANIMATION & perm)        {            llOwnerSay(llGetScriptName() + " has PERMISSION_TRIGGER_ANIMATION perms for  "+(string)llGetPermissionsKey());            /* You don't want to start the timer here; wait until listen() hears something:            llSetTimerEvent(2);            */        }        if (perm == 0)        {            llOwnerSay(llGetScriptName() + " has NO perms for  "+ (string)llGetPermissionsKey());        }        llListen( 0, "", llGetOwner(), "" );      }    listen(integer channel, string name, key id, string message)    {        llSay(0, message);        list input = llParseString2List(message, [" "], []);        string gate = llList2String(input, 0);        string action = llList2String(input, 1);        llSay(0, (string)gate);        if (gate == "off")        {            llListenControl(Handle, FALSE);        }        else if (gate == "express"|| gate == "xpress" || gate == "x")        {            /* already did these:            list input = llParseString2List(message, [" "], []);            action =  llList2String(input, 1);            */            llSay(0, (string)action);            if (action == "ah")            {                /*                 anilist = llList2List(ah,0,55);                change to: */                anilist = ah;            }            else if (action == "oh")            {                /*                anilist = llList2List(oh,0,55);                change to:                */                anilist = oh;            }            else            {                llSay (0, "Not a recognized face command. Give permission (again) and try again using one of these ...");                 llResetScript();            }//          { // Qie: you don't want to start a new block here, so no "{"            integer length = llGetListLength(anilist);            llSay(0,(string)action + " is " + (string)length + " units long and its sequence is  " + (string)anilist);/*  Qie: Let's not get tricky with this timer initiation thing for now                {                    gON = !gON;                    gCount = 0;                     llStartAnimation(llList2String(anilist, 0));                     llSetTimerEvent(0.1* gON);                }                {                    gON = TRUE;                    gCount = 0;                     llSetTimerEvent(2.0);                }    Qie: Let's just keep it simple for now:*/            gCount = 0;            llStartAnimation(llList2String(anilist, 0));            llSetTimerEvent(2.0);// End of simplified timer initiation.// That's all we're doing in this listen() event handler,// so close off with "}" until balanced and we can start a new event:        }   // closes "else if (gate == ...) {"    }   // closes "listen (...) {"    timer()    {        integer i = ++gCount;        /* don't need a new block here        { */        llStopAnimation(llList2String(anilist, i-1));        /*         } */        integer length = llGetListLength(anilist);  // Qie added; need it in this scope, too        if (i < length)        {            llSay(0, (string)i + (string)llList2String(anilist, i)); // say the ani # & name            llStartAnimation(llList2String(anilist, i+1));        /* don't close other blocks        }        }                                                                  }   just close the if() : */        }          else        {            llSay (0, "Not a face command. Give permission (again) and chat an \"x\", or \"xpress\" ot \"express\" to start, and then the command");             llResetScript();         }    }}

 

  • Like 1
Link to comment
Share on other sites

Thanks, Qie Niangao, for taking the time to read my poorly formatted script and, not only suggesting a fix but simplifying  it ... and explain where I've gone wrong.
Clearly, I need to understand the basic structure of LSL before I try another "transplant" (from individual touch buttons to an all encompassing chat).
It's now working and I understand why!

And also, thanks to  "outtaspace". If I had followed the indentation editor, I may have noticed the "event inside event error".

I'm learning a lot.

Link to comment
Share on other sites

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