Jump to content

llSetTimerEvent - firing immediatly


NellFury
 Share

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

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

Recommended Posts

I'm writing a calculator with a menu function.

Whenever I call the timer with llSetTimerEvent, the timer fires immediatly and again after the specified interval.  This seems contrary to the documentation and examples I'm seeing.

So, if I write this code:

                 llDialog(llGetOwner(), "Choose an option", ["A", "B"], menuChannel);

                 llSetTimerEvent(60.0); // Set timeout

And after that, clean up the listener in the timer event, the timer fires immediatly, killing my listener, and again at 60 second intervals.

Is this correct behaviour?  The documetation for llSetTimerEvent seems to suggest the timer event should only occur after the specified period, not immediatly.

Link to comment
Share on other sites

As a follow up, I tried this example from the wiki page on llSetTimerEvent

It fails too...  The timer event does fire, every time the llSetTimerEvent call is made

// The timer event will never fire.
default
{
    state_entry()
    {
        llSetTimerEvent(5.0);
        // Sensor every 2.5 seconds
        llSensorRepeat("", NULL_KEY, FALSE, 0.0, 0.0, 2.5);
    }
 
    no_sensor()
    {
        llSetTimerEvent(5.0);
    }
 
    timer()
    {
        llSay(0, "I will never happen.");
        llSay(0, "Well, unless llSensorRepeat() magically finds something,"+
                    "or maybe there's 2.5+ seconds of lag and the timer()"+
                    "event queues.");
    }
}

Link to comment
Share on other sites

It's impossible to answer a question like this without seeing the actual code.  Your generic description doesn't give any way to evaluate the logic of the script.  A timer event does, in fact, fire at the end of the period that you set with the llSetTimerEvent function, but it sounds like your script is written to fire it early somehow.  Maybe it has something to do with "And after that, clean up the listener in the timer event", whatever you mean by that.  Feel free to post your script (or at least relevant parts of it) here.

Link to comment
Share on other sites

Thanks, I posted another example, but here is the complete version of the code I started with...

 

//
// Counter Script
//
// Nell Fury (nellfury) 2016
//
// Test script for counter functions


// Global variables

string Ayy; // Option 1
string Bee; // Option 2

integer Listener; // Listener identity for menus

string textFunction; // Idetifier for the text functions

// end variables

 

// Constants
            
vector white_A             = <1, 1, 1>;          //ColorPaletteEntry17, "White"
vector light_yellow        = <1, 1, 0.5>;        //ColorPaletteEntry25
vector red                 = <1, 0, 0>;          //ColorPaletteEntry19, "Red"

integer menuChannel = -935756365;   // Fixed comms channels
integer textChannel = -415559366;

// end constants


// Functions

nfTextBox(string textMsg, string menuOpt)
{
 llListenRemove(Listener); // Clean up the menu listener
 Listener = llListen(textChannel, "", llGetOwner(), ""); // Make a new one
 llSetTimerEvent(60.0);  // Set timeout
 llTextBox(llGetOwner(), textMsg, textChannel);
}


nfOutput()
{
         llOwnerSay("Ayy = " + Ayy + "; Bee = " + Bee);
}

// end functions


default
{
 state_entry()
 {
  llListenRemove(Listener);   // Make sure we're clean
     }


 touch_start(integer total_number)
 {
  llListenRemove(Listener);  // Make sure we're clean
  textFunction = "";
   
  if(llDetectedKey(0) == llGetOwner()) // Only respond to owner
  {
          Listener = llListen(menuChannel, "", llGetOwner(), "");
                 // Send a dialog to owner, use a fixed negative channel number for simplicity
                 llSetTimerEvent(60.0); // Set timeout
                 llDialog(llGetOwner(), "Choose an option", ["A", "B"], menuChannel);
  }
 }


        listen(integer chan, string name, key id, string msg)
        {
                llOwnerSay("listen started");

                if(chan == menuChannel)
                {
                        if(msg == "A")
                            textFunction = "A";
                        if(msg == "B")
                            textFunction = "B";
                }

                if(chan == textChannel)
                {
                        if(textFunction == "A")
                            Ayy = msg;
                        if(textFunction == "B")
                            Bee = msg;
                        textFunction = "";
   nfOutput();
                }           

                // Fire the timer  and clean-up
                llSetTimerEvent(0.1);
        }


        timer()
        {
  //      Stop listening
                llListenRemove(Listener);
                if(textFunction != "")
   nfTextBox("Enter a value for " + textFunction, textFunction);
  // Clean up function after use
  textFunction = "";
                llSetTimerEvent(5);
  llOwnerSay("performing calculations on self timer…");
        }

}

Link to comment
Share on other sites


NellFury wrote:

As a follow up, I tried this example from the wiki page on
llSetTimerEvent

It fails too...  The timer event does fire, every time the llSetTimerEvent call is made

// The timer event will never fire.

default

{

   
state_entry
(
)

   
{

       
llSetTimerEvent
(
5.0
)
;

       
// Sensor every 2.5 seconds

       
llSensorRepeat
(
""
,
NULL_KEY
,
FALSE
,
0.0
,
0.0
,
2.5
)
;

   
}

 

   
no_sensor
(
)

   
{

       
llSetTimerEvent
(
5.0
)
;

   
}

 

   
timer
(
)

   
{

       
llSay
(
0
,
"I will never happen."
)
;

       
llSay
(
0
,
"Well, unless llSensorRepeat() magically finds something,"
+

                   
"or maybe there's 2.5+ seconds of lag and the timer()"
+

                   
"event queues."
)
;

   
}

}

Oops.

This example is clearly incorrect.  The timer will always fire, at 5.0 second intervals.  I have no idea why such a bad example would be in the wiki.

Link to comment
Share on other sites

Thanks again, but that's one of the examples at http://wiki.secondlife.com/wiki/LlSetTimerEvent

I still have the problem that my timers seem to fire as soon as I make the call to llSetTimerEvent.  Am I doing something wrong, or is there some alternative method to make the timer event only fire after the elapsed time?

I'd be happy to demostrate this.

Link to comment
Share on other sites

Your script runs, as far as it goes, and I don't see anything wrong with it.  You do start a timer with the statement in your touch_start event

llSetTimerEvent(60.0); // Set timeoutllDialog(llGetOwner(), "Choose an option", ["A", "B"], menuChannel);

When 60 seconds are up, nothing happens unless you have resonded to the Dialog prompt, because of the if statement in the timer event itself

                if(textFunction != "")

If you respond to the dialog prompt, though, the timer event's period is reset by your statement in the listen event

                // Fire the timer  and clean-up                llSetTimerEvent(0.1);

So you get an immediate response.  For right now, until you finishing writing your script, all it will do is repeat "performing calculations on self timer…" every 5 seconds, because that's the new period that's set in the timer event itself.

 

 

 

Link to comment
Share on other sites

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...