Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Is this the best way to trigger a daily event?

Torin Golding
Misanthropic Humanist
Join date: 13 Sep 2005
Posts: 41
09-25-2006 13:45
Basically I want a prim to display a daily message (which i've substituted as llSay(0,"It's a new day!";); in the example below for simplcity). I want the message to automatically change as the day (in SL/PT time) changes, although as close as I can come I think is 11:59pm-ish, which is totally fine.

Is this the best way to do this in SL?


CODE



default
{
state_entry()
{
llSetTimerEvent(60); //Initial time limit to get the first instance of 11:59pm-ish
}

timer()
{

t = (integer)llGetWallclock();

if ( t > 86330 ) //One minute and ten seconds before midnight (to make sure the firing timer hits it) (86400 seconds in a day - 60 seconds to get 11:59pmm - 10 secs for buffer)
{

llSay(0,"It is a new day");
state dailyfire;
}
else
{}
}
}

state dailyfire

{
state_entry()
{
llSetTimerEvent(86400); //To cut down on server load, fire only once a day, at the same time set by the default state, 11:59pm-ish, once the default state establishes the time.
}

timer()
{


llSay(0,"It is a new day"); //Will revert back to default state on sim restart presumably to deal with any down-time
}

}




Also am I right in thinking a timer event that fires every 86400 seconds is less load on the server than one that fires every 60 seconds to check the wallclock?

Thanks so much for any help!!
Vares Solvang
It's all Relative
Join date: 26 Jan 2005
Posts: 2,235
09-25-2006 13:59
I have a picture board that changes every day and it uses this method (the timer counting to 86400) to do it. It works, however it doesn't change at the same time everyday. Whenever the lindens take the grid offline, it resets the time that the script will change.

It works fine for my picture board since I don't care about the exact time it changes, but if it's important for the script to change at a specific time every day this method is not reliable at all.

Edit:Hmm...looking at your script a little closer I am not sure if using the llGetWallclock function as a reference will solve this problem or not. I suppose if you set your second timer to fire every hour instead of once a day that would work. Hmm...the more I look at this the more I think it will probably work.
_____________________
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
09-25-2006 18:57
For precision needs, like to change at exactly midnight... folks use a stepped timer. For example:

The timer triggers every 60 minutes and checks the time. If the time is within the 23rd hour, then the timer steps to a 15 minute interval... the interval gets shorter and shorter as the clock nears midnight. During the final 30-seconds, the timer may run every second until midnight... at which timer, the interval gets reset to 60 minutes or greater.
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
09-25-2006 22:19
It would seem to me, and I had planned to do this myself as a matter of fact.. Set a timer to go off at midnight or shortly thereafter, of doing this.

Call the llGetWallClock and find out how many seconds it is currently from the last midnight.

Subtract this number from your 86400

Subtract a few more seconds if you feel you need to, as a buffer.. Just know that the time it takes from the llGetWallClock to the llSetTimerEvent may vary depending on current server load.

then llSetTimerEvent(newtime)

anyone know of any reason why this wouldn't work? How would server resets effect this? Wouldn't it reset the script and thus recalculate the time anyway?

Example:
CODE

float buffer = 1.0; // Adjustable buffer

default
{
state_entry()
{
llSetTimerEvent(86400 - buffer - llGetWallclock());
}

timer ()
{
//Do whatever
}
}
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
09-26-2006 16:37
I believe that if the sim lags, then the timer will lag. If the sim runs at 50% for 1 minute each hour of the day... then your timer would be off by 12 minutes at the end of the day... losing 30-seconds each hour.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
09-26-2006 17:00
And if the sim stops for an hour for an upgrade, your timer will be off by an hour. A stepped timer is a good idea. If you don't do that, you could still re-check the remaining time ad start a fresh timer every time you wake up. That way, any error that might have occured in the last run, gets cleared up. If you never check, then you can never correct, and the system can drift over time.
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
09-26-2006 17:12
From: Ziggy Puff
And if the sim stops for an hour for an upgrade, your timer will be off by an hour. A stepped timer is a good idea. If you don't do that, you could still re-check the remaining time ad start a fresh timer every time you wake up. That way, any error that might have occured in the last run, gets cleared up. If you never check, then you can never correct, and the system can drift over time.


If the sim stops for an hour, and restarts, woudln't that reset the script and thus refresh the the timer anyway? Or can it stop without resetting?

As for the drift due to lag this could be checked against easily in the timer event by doing the math again and setting the timer for the remaining amount of time.

CODE

default
{
state_entry()
{
llSetTimerEvent(86400 - llGetWallclock());
}

timer()
{
if ((86400 - llGetWallclock()) >= 60) // within a Minute is accurate enough
{
llSetTimerEvent(86400 - llGetWallclock());
}
else
{
// do stuff here
// including resetting the timer event if desired
}
}
}


The only thing this doesn't correct for, is if the timer event doesn't occure till after midnight. For that, you may want to store the date and check against the date as well.

Edit: just realized that's what you meant.. best use this to get you within an hour then step down i guess.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
09-26-2006 17:21
From: someone
If the sim stops for an hour, and restarts, woudln't that reset the script and thus refresh the the timer anyway? Or can it stop without resetting?


I believe scripts are 'frozen in time' while a sim is down, and pick back up from where they stopped when the sim comes back. I could be wrong.

And yes, the check you added - that's exactly what I was talking about :)
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
09-27-2006 01:06
Sims stopped for some reason give scripts frozen in time, including timers.

I use a long run timer (secs in day - timestamp) in some things where the response isn't critical for time. Downtime for upgrades delays the scripts by a few hours (usually about 1, but more for some of the recent ones), downtime for sim crashes etc. usually delays by a few tens of minutes.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog