|
Lewis Nerd
Nerd by name and nature!
Join date: 9 Oct 2005
Posts: 3,431
|
03-04-2006 10:19
Is it possible to read the clock - either game time or system time - and use that to trigger an event?
I've just build a bell tower on my property, and have put a script in it so when you touch the bell, the bell rings 3 times.
However, I thought it would be nice if the bell would ring every 15 minutes automatically in sync with the clock, as a feature. It's not very loud so it won't disturb the neighbours.
I know I can set it on a timer of some sort and just leave it running... but I thought reading the clock would be a neater method.
Any suggestions?
Lewis (WWID)
|
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
03-04-2006 11:39
Im afraid there's no event that triggers with respect to a static clock; the timer event is all we have, and that's subject to time dialation. Here's my idea: use a timer that checks llGetWallclock every 30 seconds, executing the ring if the current llGetWallclock is currently a multiple of 15. integer prevRing = -1; integer RING_INTERVAL = 15; // minutes
default { state_entry() { llSetTimerEvent(30); } timer() { integer minutes = (integer)(llGetWallclock() / 60); if (minutes % RING_INTERVAL == 0) { // Ring. } } }
I think that should work - it wont be the most efficient thing out there, but it should at least be reasonably accurate. ==Chris
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
03-04-2006 11:59
integer RING_INTERVAL = 15; // minutes
time_sync() // Figure out how many seconds to next chime, and set the timer event for it { integer seconds_used = ((integer)llGetWallclock()) % (RING_INTERVAL * 60); llSetTimerEvent((RING_INTERVAL * 60) - seconds_used); } default { state_entry() { time_sync(); // first time through } on_rez(integer p) { time_sync(); // Who knows how long we were in inventory } timer() { // Ring. time_sync(); // And the event might have been delayed... } }
More accurate and MUCH more efficient!
|
|
Lewis Nerd
Nerd by name and nature!
Join date: 9 Oct 2005
Posts: 3,431
|
03-04-2006 12:00
That's exactly what I needed - thanks very much!
The only change I made was in the line
llSetTimerEvent(30);
I found that it would play the sound, wait for 30, then it would realise it was still in the same minute it played it again - so I changed the 30 to 55 and it seemed to work just fine.
Thanks very much!
Lewis (WWID)
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
03-04-2006 14:31
Changing it to 55 seconds means that it will still ring twice... about 1 time out of 20 instead of every time.
Try my version. Instead of waking up every minute and being up to a minute off, it wakes up once every quarter of an hour and is never more than a second off.
Remember all those threads about optimizations? This is the kind of optimization that gives you a big win. It uses 15 times less CPU and is 60 times more accurate!
|
|
Lewis Nerd
Nerd by name and nature!
Join date: 9 Oct 2005
Posts: 3,431
|
03-04-2006 15:03
Thanks!
Lewis
|