Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Question about random lllFrand

Tuber Potato
Registered User
Join date: 26 Jan 2006
Posts: 57
12-19-2006 15:33
Quick question about llFrand:

In the example below, if I am not mistaken, an random number will be generate ONCE then used repeatedly... OR, will the random number be re-generated each time the "timer" is set off?

CODE
default
{
state_entry()
{
llSetTimerEvent(llFrand(30-15)+15);
}

timer()
{
llSay(0, "The timer has gone off.");
}
}
Peekay Semyorka
Registered User
Join date: 18 Nov 2006
Posts: 337
12-19-2006 16:02
In your example, the random number is generated once, and used once. The timer will be fired repeatedly.

-peekay
Tuber Potato
Registered User
Join date: 26 Jan 2006
Posts: 57
12-19-2006 16:05
but in my example, the number gets randomly generated once, and for example picks 21.

Then the Timer will fire ever 21 seconds from there on out, Right?
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-19-2006 16:36
From: Tuber Potato
but in my example, the number gets randomly generated once, and for example picks 21.

Then the Timer will fire ever 21 seconds from there on out, Right?


Yes, which is what Peekay said.
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
12-19-2006 17:03
Just in case you are actually looking to generate a different random number for each iteration of the timer, here's how you'd do it.

CODE

default
{
state_entry()
{
llSetTimerEvent(llFrand(30-15)+15);
}

timer()
{
llSay(0, "The timer has gone off.");
llSetTimerEvent(0); // stop the timer
llSetTimerEvent(llFrand(30-15)+15); // restart timer with a new random number
}
}
Tuber Potato
Registered User
Join date: 26 Jan 2006
Posts: 57
12-19-2006 17:48
Thanks Guys,

I'm still somewhat new to LSL after a 15 year break from Turbo Pascal. LOL.

Just wanted to make sure I understood. Thanks for the method to reset the time too, btw.

Tuber
Peekay Semyorka
Registered User
Join date: 18 Nov 2006
Posts: 337
12-19-2006 20:34
There is no need to stop the timer with llSetTimerEvent(0) before setting it to a new value.

-peekay
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-20-2006 02:29
A couple of things that no one has pointed out (including me)
You need to put spaces around the minus in (30-15) or the compiler will give you a weird error emssage. But you should really be writing it as just 15, why use up extra memory you dont need to.

CODE

default
{
state_entry()
{
llSetTimerEvent(0.1); // Force the timer to fire almost immediately
}

timer()
{
llSay(0, "The timer has gone off.");
llSetTimerEvent(llFrand(15)+15); // restart timer with a new random number
}
}