Jump to content
mySky Phenomena

Using a timer event for removing listens and other things at the same time

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

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

Recommended Posts

Hello All,

I have a little bit of experience scripting using LSL, but I think I'm not understanding either how the timer event works or how to properly remove listeners. When trying to learn how to build a dialog menu, I read many resources that said removing open listeners is very important. In all of my scripts up until now, I've been using a timer event in case the user doesn't click on the menu, like this:

open_menu(variables)
{
	//Do stuff with variables to open a dialog menu
	llSetTimerEvent(30.0);
}

close_menu()
{
	//remove listeners
	llSetTimerEvent(0.0);
}

default
{
	//Code

	timer()
	{
  		close_menu();
	}
}

However, now I need to use the timer event for something else. I've seen other posters on here using a counter in the timer event when they need multiple timer events (I know you can't literally have multiple timer events), like this:

default
{
    //Code

    timer()
    {
        ++counter;
        if(counter == max)
        {
            //Do something else
        }
        //Do something
    }
}

I don't think I understand how this works. For example, let's say my "main use" for the timer event is to blink a light every 5 seconds, but there's a menu as well that asks the user if they want the light to blink or not. Do I set this counter to zero when the menu is opened and then set whatever "max" value?

I know the blue menu won't go away if counter reaches "max," but I want to make sure there aren't any open listeners if the user doesn't click anything.

Let me know if I'm not making sense, or if there's another post I missed. Thanks!

Share this post


Link to post
Share on other sites
Posted (edited)

You're right that a script can only run one timer event at a time.  However, there are several ways to get around that limitation.  See my summary here>>> 

and the posts that follow it.

"Do I set this counter to zero when the menu is opened and then set whatever "max" value?"

Yes, exactly.

"I know the blue menu won't go away if counter reaches "max," but I want to make sure there aren't any open listeners if the user doesn't click anything."

So that's what you do in the place where you have the comment //Do something else.  

 

Edited by Rolig Loon
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

In some of my scripts I am using the timer for many things at once. 

Usually the way I go about it is to keep a strided list of queued timer tasks and the timestamp at which the event should occur.

When the timer event fires, I do whatever is the first item in the list, then remove it from the list. I look at the timestamp of the next event if there is one, and set a timer based on the difference between that timestamp and the current timestamp. 

Share this post


Link to post
Share on other sites

That's pretty much how I do it too.

I've posted my version of a multiple timer in this LSL Library forum thread: 

 

Share this post


Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 88 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...