Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Lsl / Host / Cron

Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
09-16-2008 05:40
Hello everyone, I have to make a system and I need to use 'cron', and I have some questions for you:

What I need to do is have some scripts restarting each 24 hs / 7 days / 1 month and two month. So I thought using cron for that.

On the first case for example:
Everyday 23:59 will send a mail to the object containing the script

Second example:

The 7th day of week 23:59 will send a mail to the object ocntaining the script and so on.

So, in world I would need a script with a timer tiggering llGetNextMail(); function.

My question is: How to avoid a timer checking constantly for an event that will happen in 24hs/7 days/30 days. Is there another way to do this?
_____________________
Jocko Domo japanese goods



[Blog]
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
09-16-2008 06:23
Up
_____________________
Jocko Domo japanese goods



[Blog]
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
09-16-2008 07:20
Use a Timer of 86400 to count the days that have passed since the script reset?

Or... Compare llGetDate with a recorded date on a shorter timer and increment (and store the new date) the days counter that way, so you'll be fairly close to Midnight UTC for your rollovers.

The latter plus llSetObjectDesc with the date and number of days passed is more resilient to unintended resets and stuff aswell. (Setting Desc you'd need to reset your counter before the reset triggers.)
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
09-17-2008 09:04
My question was how to avoid using short period timers, and it seems there is no way to do it.

But what I thought is:

Count days as you specified in the script, then when the count gets to lets say '30' it will start counting with shorter intervals until it gets to 23:59.

I don't see a better solution to this.
_____________________
Jocko Domo japanese goods



[Blog]
Alicia Sautereau
if (!social) hide;
Join date: 20 Feb 2007
Posts: 3,125
09-17-2008 09:19
there is another solution wich is unix timestamps

as i got to run for work, i`ll make it short but hope you get the idea, there is also an LSL function for it and user created functions to check dates on the wiki, but here`s the idea:

timer()
{
if (now() > next_update) {
//make http call and parse all the stuff

next_update = next_month(next_update)) // make the next update next month (can be done php or lsl function, i do php)
}
}

php and lsl combined lol
but the timer just checks the date in timestamp and if now is greater then next_update, execute the update and reset next_update with the timestamp of next month`s date, use a php function to save script resource for an exact date:time and execute the timer ever 10-30-60 minutes (or how ever you see fit)

/runs off
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
09-17-2008 18:02
You should be able to set a long-period timer, but the tricky bit is that timers are influenced by time dilation. So setting a shorter timer is a way of mitigating the risk of a ton of lag over a long period of time.

If you wanted to do something in 4 days, setting a timer for exactly a 4-day period is betting on the time dilation being an average of 1.0 over those 4 days. If in actuality the average time dilation were 0.8 over those 4 days, your error would be (4 days)/0.8 - 4 days = 1 day. Ouch! (Though an average time dilation of 0.8 over 4 days would frankly stink, and would very much surprise me.)

Let's assume, on the other hand, that you used two periods: 0.8 of 4 days, then whatever time is left after the first timer executes. Then if time dilation were 1.0, the second timer would be dead on. If time dilation were 0.8, then the first timer would be dead on. If the time dilation were 1.0 during the first period but 0.8 during the second 0.2*(4 days) = 0.8 days period, you'd be off by only (0.8 days)/0.8 - 0.8 days = 0.2 days or about 5 hours (a lot better than a whole day).

I think a good strategy would be to use a conservative guess on average time dilation based on your knowledge of the region's general amount of lag (heck, measure it then pad the result a bit!), and repeat until you get under a certain threshold that will give you the kind of accuracy you want. Something like (note: not yet compiled, so some minor fixes may be needed):

CODE

float WAIT_PERIOD_FRACTION = 0.8;
float MIN_PERIOD = 5.0;

// Returns exactly 0.0 when we are done waiting; otherwise returns the next timer period to use
float nextTimerPeriod(integer desiredTimestamp)
{
integer currTimestamp = llGetUnixTime();
float timeLeft = desiredTimestamp-currTimestamp;
if (timeLeft <= 0.0)
{
return 0.0;
} else if (timeLeft < MIN_PERIOD)
{
return timeLeft;
} else
{
return WAIT_PERIOD_FRACTION*timeLeft;
}
}