Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Timers help

Lewis Nerd
Nerd by name and nature!
Join date: 9 Oct 2005
Posts: 3,431
07-09-2006 07:41
Ok... I'm using regular timers using llSetTimerEvent(10); and timer().

However, I have 4 "states" and each of them need to be a different length. Two would be just "x", one "2x" and one "5x" or thereabouts.

I wondered if it's possible to easily add in a 'timer multiplication factor' or some other tweak to achieve this, so that each 'state' may pause for a different time - at the moment the llSetTimerEvent (x) appears to be a global variable.

I've already tried timer() on two separate lines and it didn't want to co-operate - unless that's the way and I'm just doing something wrong.

Would it be as simple as making a state "wait" and calling that before going to the next section?

Any help gratefully appreciated. What I have works, but with the above it would work better.

Lewis
_____________________
Second Life Stratics - your new premier resource for all things Second Life. Free to join, sign up today!

Pocket Protector Projects - Rosieri 90,234,84 - building and landscaping services
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
07-09-2006 07:56
/54/d7/110734/1.html
Bitzer Balderdash
Dazed and Confused
Join date: 21 Dec 2005
Posts: 246
07-09-2006 07:56
if you mean states in the lsl state foo; sense, then...

the timer setting persists over states, BUT the timer() event handler needs to exist in each of them.

the easiest way to do it would be to have an llSetTimerEvent() of an appropriate length in the state_entry() for each of your states.

alternatively, have a global variable called, say, multiplier, that counts down in the timer() handler in every state, which you can then zero-check and act as necessary, which you can initialise in state_entry().

Not entirely sure what you are asking though, but I hope that helps.
Lewis Nerd
Nerd by name and nature!
Join date: 9 Oct 2005
Posts: 3,431
07-09-2006 08:31
Joannah..... I've tried reading that and I can't get me head round it sorry. But thanks for finding it.

Bitzer.... if you can contact me in-game I'll gladly explain more - as I will to anyone else who would like to help.

Why is LSL so complicated? What's wrong with the good old BASIC command of PAUSE x where x is the amount of seconds to wait, which can be different each time the command is used.

This seems one of those things where LSL is unnecessarily complicated for no obvious reason.

Lewis
_____________________
Second Life Stratics - your new premier resource for all things Second Life. Free to join, sign up today!

Pocket Protector Projects - Rosieri 90,234,84 - building and landscaping services
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
07-09-2006 08:47
From: Lewis Nerd
Joannah..... I've tried reading that and I can't get me head round it sorry. But thanks for finding it.

Eek, sorry... it basically boils down to:

* a timer is triggered every X seconds. in your case it would be every 10 sec.
* then in the timer event, there's series of checks performed
- events that happen every 10 sec are triggered with every timer event
- events that happen every 2x 10 seconds are triggered every 2nd timer event
- events that happen every 5x 10 seconds are triggered on every 5th timer event
* etc

more specifically, your code would be like:
CODE

float FREQUENCY = 10.0; //one tick every 10 seconds
integer counter = 0; // time accumulator

default {
// somewhere in your code the timer event is triggered
state_entry() { llSetTimerEvent( FREQUENCY ); }

// then the actual timer event is handled
timer() {

++counter;

// first you can do everything that happens every timer tick
// put the code here to launch functions, or whatever

// then we check if it's right time to trigger more rare events
if( counter % 2 == 0 ) { // execute the 'every 2nd timer' thing }
if( counter % 5 == 0 ) { // execute the 'every 5th timer' thing }
// etc
}
}


From: someone
Why is LSL so complicated? What's wrong with the good old BASIC command of PAUSE x where x is the amount of seconds to wait, which can be different each time the command is used.

You have llSleep() which works just like PAUSE, but i wouldn't call this an easier approach when you have multiple things to occur at various intervals... since figuring out just for how long you should pause could be quite a pain o.O;

edit: but on second thought, what you're after is more akin to what Bitzer describes... so his approach is probably better suited for your goals.
Lewis Nerd
Nerd by name and nature!
Join date: 9 Oct 2005
Posts: 3,431
07-09-2006 09:17
llSleep works just how I wanted... as always I forgot the obvious :) If anyone would like to see what it's all about, IM me in game, if I'm online but I'm not all set up where I am, then I can easily do a quick demo.

Lewis
_____________________
Second Life Stratics - your new premier resource for all things Second Life. Free to join, sign up today!

Pocket Protector Projects - Rosieri 90,234,84 - building and landscaping services