Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help with time triggered script

HolyHell Cassell
Registered User
Join date: 2 Aug 2006
Posts: 166
12-22-2006 05:59
Hey guys. I cant find anything that will do this, and Ive been thru the forums all morning...

So here's what I need... A script that will play a sound every hour on the hour according to SL time. (well I guess any time would do since its hourly heheheh)

Help ? :)
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-22-2006 08:34
From: HolyHell Cassell
Hey guys. I cant find anything that will do this, and Ive been thru the forums all morning...

So here's what I need... A script that will play a sound every hour on the hour according to SL time. (well I guess any time would do since its hourly heheheh)

Help ? :)



Not 100% accurate but try

CODE

integer SecHr = 3600;

default
{
state_entry()
{
integer time = (integer)llGetWallclock();
integer nexthr = SecHr - (time % Sechr);
llSetTimerEvent(nexthr);
}

timer()
{
llPlaySound("sound",1.0);
llSetTimerEvent(SecHr);
}
}
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
12-22-2006 09:02
This is certainly the right idea. How accurate do you need? If it needs to be more accurate, then perhaps you should check more often.

Another approach, in words, not LSL, would be

CODE
forever
{
compute time to next hour
sleep for that length of time
do something
}

again, if you need accuracy, you might want to wake up and recompute more often.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-22-2006 10:05
From: Lee Ponzu
This is certainly the right idea. How accurate do you need? If it needs to be more accurate, then perhaps you should check more often.

Another approach, in words, not LSL, would be

CODE
forever
{
compute time to next hour
sleep for that length of time
do something
}

again, if you need accuracy, you might want to wake up and recompute more often.



Was reffering to the 'time drift' that has been spoken about previously. Teh code should work to within a few seconds which I hope is accurate. Not sure if a sleep would be less of a resource hog than a timer since it wouldnt use an overt event. ?
HolyHell Cassell
Registered User
Join date: 2 Aug 2006
Posts: 166
12-22-2006 10:37
Well idealy what i would like it to do is play a sound pretty regularly on the hour ( for this purpose, a bell tower for a clock) . So it would need to be pretty accurate. Also for bonus points, if theres some little script wiz out there that could tell me how to get it to play the sound based on the hour (1pm would play the sounds once, 4pm plays it 4x etc.....) that would sooooo rock :)
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-22-2006 11:12
From: HolyHell Cassell
Well idealy what i would like it to do is play a sound pretty regularly on the hour ( for this purpose, a bell tower for a clock) . So it would need to be pretty accurate. Also for bonus points, if theres some little script wiz out there that could tell me how to get it to play the sound based on the hour (1pm would play the sounds once, 4pm plays it 4x etc.....) that would sooooo rock :)



CODE

integer SecHr = 3600;

default
{
state_entry()
{
integer time = (integer)llGetWallclock();
integer nexthr = SecHr - (time % Sechr);
llSetTimerEvent(nexthr);
}

timer()
{
llSetTimerEvent(SecHr);
integer time = (integer)llGetWallclock();
integer hrs = time / SecHr;
if(hrs > 12)hrs -= 12;
while(hrs)
{
llPlaySound("sound",1.0);
llSleep(2);
--hrs;
}
}
}
HolyHell Cassell
Registered User
Join date: 2 Aug 2006
Posts: 166
12-22-2006 14:15
Thank you Newgate ! Will give that a shot and see if thats what Im after. Much appreciated !
Infrared Wind
Gridologist
Join date: 7 Jan 2007
Posts: 662
03-16-2009 06:35
From: Newgate Ludd

integer nexthr = SecHr - (time % Sechr);


There's a small problem with the script. It should be:

integer nexthr = SecHr - (time % SecHr);

Note the case of "H" in the second instance of the var SecHr.

- i
_____________________