Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Lag-Free Midnight Timer Script

Mathieu Basiat
Wavemaster
Join date: 24 Apr 2006
Posts: 57
06-19-2006 12:08
What is the best way to have a script run at midnight PST every night that is lag free (ie timer event is 24 hours long) and will be problem free after sim crashes and restarts?
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
06-19-2006 12:12
Have one that, on state_entry, calculates the number of seconds to midnight, then sets a timer for that length of time. Once the timer triggers and does whatever you want to do at midnight, it can reset the timer to whatever 24 * 60 * 60 is. It should also reset itself on_rez.

If the sim is reset that should keep on working I'd think.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
06-19-2006 16:44
I use the method that Ordinal recommeds. Not sure about resets, but when the grid goes down for a new version the next day the emails it sends are all late, usually by about 2 hours.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
06-20-2006 07:40
From: Ordinal Malaprop
Have one that, on state_entry, calculates the number of seconds to midnight, then sets a timer for that length of time. Once the timer triggers and does whatever you want to do at midnight, it can reset the timer to whatever 24 * 60 * 60 is. It should also reset itself on_rez.


Perhaps also confirm the actual time just before executing the task to ensure that the timer does not drift from executing the task at midnight. In this case, the event could still drift but should correct itself after the task executes so that the drift does not propogate into subsequent days.

-2fast
Mathieu Basiat
Wavemaster
Join date: 24 Apr 2006
Posts: 57
06-20-2006 11:53
So what is the best way to get time until midnight?
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
06-20-2006 12:00
CODE
float seconds_until_midnight = 86400.0 - llGetWallClock();

86400 is the number of seconds in a day, and llGetWallClock() returns the number of seconds since midnight (in SL time).
Mathieu Basiat
Wavemaster
Join date: 24 Apr 2006
Posts: 57
06-21-2006 16:11
works! thx!
Kokiri Saarinen
Quoted for truth
Join date: 7 Jan 2006
Posts: 44
06-23-2006 00:29
If you want a less laggy solution than using a timer, you can have it sleep. Find out the amount of time until midnight once, tell it to sleep for that long, then itll come out of the sleep at midnight. At this point, you can run your midnight code, and tell it to sleep for another 24 hours. A very simple while loop.

-Kokiri
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
06-23-2006 09:47
Why would a while loop with a sleep be any less laggy than a timer?