Jump to content
  • 0

LSL: How do I pause a timer for a menu, and then resume the timer when a button has been clicked?


monlov
 Share

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

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

Question

So, I am currently working on my second script ever (which, honestly, may be a bit above my level), using the first script (which a friend helped me with, by improving the timer, ect.) as a template.

My issue is that I make a menu open here:

        if (time == 5)
        {
            llDialog(toucher, "Select an option", tapes, channelDialog);
            listenId = llListen(channelDialog, "", toucher, "");
        }

and click the "Tape 5" button

        else if (tapes == "Tape 5")
        {
            time = 6;
            if (time == 6)
                llRegionSayTo(toucher, 0, "* Chara...");
            if (time == 7)
                llRegionSayTo(toucher, 0, "* Can you hear me?");
            if (time == 8)
                llRegionSayTo(toucher, 0, "* We want you to wake up...");
            if (time == 9)
            {
                llSetTimerEvent(0);
                time = 5;
            }
            time++; 
        }

All it does is say "Chara..." and then it does nothing.

Can anyone tell me what I am doing wrong?

 

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

It's hard to say without seeing the complete script and you'll probably get more and better replies if you repost the question (with the full script) in the LSL Scripting section of the forum.

If I understand you right, you're trying to use a timer to send a series of delayed messages. Assuming your last code snippet is inside a timer event there doesn't seem to be any fatal errors there. There are some performance issues but nothing that should keep the code from running. It is a slight possibility that you triggered the llRegionSayTo block at some point but if you did none of the messages should have gone through until the sim is restarted and I understand the first message works just fine. This is very easy to check though, just replace the llRegionSay with regular llSay functions - or just add llSay or llOwnerSay checkpoint functions to each section of the loop.

It's more likely the problem is caused by some part of the script outside the two snippets you've posted. One possible reason is that the interval is set so short the first timer event hasn't finished before the second is called.

About performance issues, use else if rather than plain if conditions whenever possible. The way your script are written, you force the poor server to run a lot of unnecessary routines. Also, make it a habit to use ++a; or a+=1;, rather than a++; for incremental changes in an integer. The performance tests done are not absolutely conclusive (and may not apply to mono) but they all indicate that a++; is the slowest of the three.

For a script like this I probably wouldn't have used a timer event at all but rather set the intervals with llSleep(); or possibly even llResetTime(); Yes, repeated sleep calls are known to be a bit laggy but compared to a string of if conditions and repeated resetting of a counter variable, it is probably still the speed winner and it certainly simplifies the code. Also, the moment you have a menu function in your script, you need the timer event to close the listen. Keeping listens permanently open is one of the big no-nos in scripting and something you only do if there is absolutely no other alternative. You can script the timer event to handle both the intervals between messages and the listens of course but the code gets complicated very fast if you do.

 


Edit: Woops I missed that line Rolig spotted. Yes, that would stop the script dead in its track. Depending on the rest of the script, it may also cause other problems since it bypasses the llSetTimerEvent(0); function.

If there's any comfort, even the best scripters spend a tremendous amount of time desperately looking for errors they can't believe they could possibly have missed once found. ;)

And as Rolig said, llOwnerSay(); is a scripter's best friend. Sometimes you just need the script to say "Hi" at a certain point just to check it gets to that point at all, sometimes you need it to check that a variable has the correct value. Only, remember to remove those OwnerSay checkpoints from the final version of th script... ;)

Link to comment
Share on other sites

  • 0

Ninety percent of scripting is logic.  The rest is details of syntax.  Except for the silly spelling errors that we all make, then, most of the problems you run into can be traced to faulty logic.  In this case, it's easy to spot the problem.  You wrote

        else if (tapes == "Tape 5")        {            time = 6;            if (time == 6)                llRegionSayTo(toucher, 0, "* Chara...");            if (time == 7)                llRegionSayTo(toucher, 0, "* Can you hear me?");

So, when script execution enters this area, the first thing that happens is that the variable time is set to the value 6. Then you immediately ask the script "What's time?".  Well, it's 6.  You just set it.  And it will always be 6 every time the script gets here.  It will never be 7 or 8 or 9, so you'll never get those messages. 

The easiest way to spot logical errors if they don't just jump out and hit you in the face is to add some llOwnerSay statements to the script at key points.  Ask the script to tell you what the value of your troublesome variable is.  I get a lot of embarrassing surprises that way.  :smileywink:

EDIT: Incidentally, one way to interrupt your timer is to stop it when time == 5 and then restart it when you hear a response to your llDialog.  

 

timer(){    if (time == 5)    {        llDialog(toucher, "Select an option", tapes, channelDialog); 
listenId = llListen(channelDialog, "", toucher, ""); llSetTimerEvent(0.0); /// Stop it here } else if (tapes == "Tape 5") { if (time == 6) { llRegionSayTo(toucher, 0, "* Chara..."); } else if (time == 7) { llRegionSayTo(toucher, 0, "* Can you hear me?"); } else if (time == 8) { llRegionSayTo(toucher, 0, "* We want you to wake up..."); } else { llSetTimerEvent(0); } } ++time;}listen (integer channel, string name, key id, string message){ if (message == "Tape 5") { time = 6; llSetTimerEvent(myTimeInterval); // Whatever your time interval was before }}

 And Chin is right.  This sort of question really belongs in the LSL Scripting forum, not in Answers.  :)

       

  • Like 3
Link to comment
Share on other sites

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