Jenny Hispidus Posted June 26, 2011 Share Posted June 26, 2011 When I use timer to have the script count down to an event, and I want to do other things as well in the intervening time, how would I accomplish that?For instance, I have a script that counts down to 60 seconds, but i'd like the object to also listen on a channel for another command, that might cause it to use llSay, or bail out of the timed event. I dont know how the logic works. Link to comment Share on other sites More sharing options...
Acheron Gloom Posted June 26, 2011 Share Posted June 26, 2011 llSetTimerEvent(float time) is the function you use to set up a timer. Every 'time' seconds it will activate the timer EVENT. To stop a timer you would just do llSetTimerEvent(0.0); or to change it ot another time you would just do the llSetTimerEvent() function again with a different time. The event will keep activating every 'time' seconds until its stopped though. Basically, start it with llSetTimerEvent(60.0); to have it activate 60 seconds later, and to stop it you would use llSetTimerEvent(0.0); If you want it to do something every second you would need a global variable integer set to 60, a timer for every second, and just do llSay(0, "COUNTER AT: " + (string)(--varInt)); if(!varInt){ we're all done } and to reset it you would stop the timer AND set varInt back to 60. Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 27, 2011 Share Posted June 27, 2011 You can multiplex a timer as much as you like. This timer manages actions every second, every ten seconds, and every minute, stopping in 5 minutes or when you click it. integer count;integer ON;default{ touch_start(integer total_number) { llSetTimerEvent(1.0* (ON = !ON)); //Turns timer ON and OFF } timer() { ++count; llSay(0,"The current count is " + (string)count); if(count%60 == 0) { llSay(0,"This message is sent once a minute"); } if (count%10 == 0) { llSay(0,"This message is sent every ten seconds."); } if(count == 300) { llSetTimerEvent(0.0); // Timer shut off in five minutes } }} 1 Link to comment Share on other sites More sharing options...
Poenald Palen Posted June 27, 2011 Share Posted June 27, 2011 You just have something in the Listen event change the time, it will stop. So, just use llSetTimerEVent(0.0) after you listen event set of checks, word verification or whatever. if(Stop = TRUE){llSetTimerEvent(0.0);} //switch off timer. Link to comment Share on other sites More sharing options...
Jenny Hispidus Posted June 27, 2011 Author Share Posted June 27, 2011 I appreciate the question but that's not what I meant. What if I want something to happen while the timer is ticking that has nothing to do with the timer? One example being .... I say "turn off!", but another example would be listening and repeating the string as a shout or something. Link to comment Share on other sites More sharing options...
Void Singer Posted June 27, 2011 Share Posted June 27, 2011 you do those as normal... that's the beauty of timer loops, they don't stay in the event between triggering... which lets other code run normally. Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted June 27, 2011 Share Posted June 27, 2011 If you use a timer, the script will do other things while the timer event isn't executed - in fact, if you want to do things between two executions of the 'loop', you have to use a timer. If you use loops like for, while .., nothing else will be done - no events are triggered while a loop loops. so in the following example, if the owner says "stop" on channel 1, it would stop the counter integer giCounter;default { state_entry() { llSetTimerEvent(5); llListen(1, "", llGetOwner(), "stop"); } listen(integer channel, string name, key id, string message) { llSetTimerEvent(0); } timer() { llOwnerSay("I am at: " +(string)giCounter); } } Whereas in this example it wouldn't: integer giRun;default { state_entry() { llListen(1, "", llGetOwner(), "stop"); integer counter; giRun = 1; while(giRun) { llOwnerSay("I am at: " + (string)counter); ++counter; llSleep(5); } } listen(integer channel, string name, key id, string message) { giRun = 0; }} Link to comment Share on other sites More sharing options...
Ferd Frederix Posted July 1, 2011 Share Posted July 1, 2011 SL scripts are event-driven. Your timer is an event. timer() gets executed only when a timeout happens. The timeout is the event, as the timer(0 function is called when the timer expires. listen(), link_message() and other events such as changed() , can occur asynchronously to other events. Only one event can be executing at a time. Anything inside of default: default() { <HERE>// code in <here> are events } is an event. And example is timer() Events operate when some kind of trigger associated with that event happens. As a rsult of this Your timer will operate independently the other events. The other posts indicate some possible ways to get the timer to 'bail out'. The simplest possible way is to llSetTimerEvent(0) in any other event to stop the timer event from happening Link to comment Share on other sites More sharing options...
Jenny Hispidus Posted July 2, 2011 Author Share Posted July 2, 2011 Thank you to everyone for answering my questions, I understand the way it all works now. Wasn't really certain what the limitations on a timer event were. Link to comment Share on other sites More sharing options...
childhoodbestfriend489 Posted March 21, 2021 Share Posted March 21, 2021 How to stop this loop? Link to comment Share on other sites More sharing options...
Profaitchikenz Haiku Posted March 21, 2021 Share Posted March 21, 2021 If it's a for loop or a while loop that has a counter (index) that is compared against and upper limit (indexMax), then inside the loop, set index to be equal to or greater than indexMax and at the next test in a for loop, the loop will terminate. If it's a do.. while or while loop that tests for a condition being true or false, set the variables to that at the next test the condition for stopping will be met. If it's an infinite loop, pulling the plug is the way to go for volatile memory, otherwise it's quite a drastic process. Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 22, 2021 Share Posted March 22, 2021 On 3/21/2021 at 9:07 AM, childhoodbestfriend489 said: How to stop this loop? What loop? In the context of this thread, script execution is not IN the timer event except in the instant after it is triggered by llSetTimerEvent. That is, if you say llSetTimerEvent(60.0) somewhere in your script, absolutely nothing related to the commands in the timer event will happen until precisely 60 seconds later. Up to that instant, your script can do all sorts of other things including shutting the timer off with llSetTimerEvent(0.0) or resetting it to a different period. The script is not in a loop in the strict sense that it would be if you used a flow control option like for or while or do while. If you do not issue a new llSetTimerEvent command, it will keep triggering the timer event every 60 seconds -- which is sort of loopy, I'll admit -- but between triggerings execution can go almost anywhere you like. Link to comment Share on other sites More sharing options...
Love Zhaoying Posted March 23, 2021 Share Posted March 23, 2021 On 6/27/2011 at 2:29 AM, Jenny Hispidus said: What if I want something to happen while the timer is ticking that has nothing to do with the timer? Easy, just trigger another event: touch, etc. Link to comment Share on other sites More sharing options...
Recommended Posts
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