These forums are CLOSED. Please visit the new forums HERE
Clock tower |
|
|
Hg Beeks
llGetElement(80);
Join date: 13 Apr 2006
Posts: 134
|
06-13-2007 22:23
I was hoping to create a sort of clock tower, but I'm unsure as to what the best method of ensuring that it goes off on the hour is. Any suggestions?
|
|
AnnMarie Otoole
Addicted scripter
Join date: 6 Jan 2007
Posts: 162
|
Go to the bible and look it up
06-14-2007 00:52
Go to http://rpgstats.com/wiki/index.php?title=Functions and click on Time to get various functions you can use.
|
|
Galbraith Karami
Registered User
Join date: 12 Dec 2006
Posts: 25
|
06-14-2007 01:30
I've already dealt with clocks, but this is quite different, and needs a different approach.
I used llGetTimeStamp cause it gives an absolute date-and-time and it's useful for clocks and such, you have to consider time zones. I won't be leading you by the hand writing the code for you (we all now a coder grows by bangng his head into problems until they're solved), but if you need more help, just ask. |
|
Hg Beeks
llGetElement(80);
Join date: 13 Apr 2006
Posts: 134
|
06-14-2007 04:44
I've already dealt with clocks, but this is quite different, and needs a different approach. I used llGetTimeStamp cause it gives an absolute date-and-time and it's useful for clocks and such, you have to consider time zones. I won't be leading you by the hand writing the code for you (we all now a coder grows by bangng his head into problems until they're solved), but if you need more help, just ask. The most likely time would be SLT, though the most important part is simply getting the time until hour itself. With the Time functions I looked at, I think it would be pretty simple to rig something up now that I look, though I'm skeptical about ensuring that it'll always be on the hour. You know how lag tends to make timing drift. |
|
Galbraith Karami
Registered User
Join date: 12 Dec 2006
Posts: 25
|
06-14-2007 10:56
Well, I guess to move the minutes hand you'll have to use a timer set to 60.0 seconds... each time you check the minute of SLT time (or use a counter variable), and when you're around 58-59 you start to check the time to the second. This way you should minimize the effects of lag, and toll your bell at the hour.
|
|
Hg Beeks
llGetElement(80);
Join date: 13 Apr 2006
Posts: 134
|
06-14-2007 12:06
Well, here's what I've got:
CODE
Only trouble is that the number of times it chimes is off. At 11 it chimed at least 20 times before I got it to stop, and at noon it chimed once. Edit: Never mind; My tests were being done at non-hour intervals; The act of subtracting current seconds from the time it was always gave it a response of 0, so the loop occurred immediately. The number of times being rung was correct. |
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
06-14-2007 14:32
24 hr clock........
_____________________
I'm back......
|
|
Galbraith Karami
Registered User
Join date: 12 Dec 2006
Posts: 25
|
06-14-2007 16:16
Ok, let's see:
instead of setTimer() { integer curTime = (integer)llGetWallclock() - (60 * 60 * ((integer)llGetWallclock() / 60 / 60)); integer timeTilHour = 3600 - curTime; llSetTimerEvent(timeTilHour); } it would be simpler as: setTimer() { integer timeTilHour = 60 * (58 - (integer)llGetSubString(llGetTimestamp(), 14, 15)); //see number of minutes until next hour, then multiply to get seconds llSetTimerEvent(timeTilHour); } while instead of integer temp = ((integer)llGetWallclock() / 60 / 60); you can of course use integer hour = (integer)llGetSubString(llGetTimestamp(), 11, 12) + (time zone); //must compensate for GMT / PST time zone difference... 24 hr clock... That's right, the problem of the number of chimes is because they all correspond to the hour, except when you need twelve and instead you could have 00 or 12. Not to mention when it will start chiming fifteen times at three PM! So I developed a simple algorithm that can solve that; you'll have to check with an IF for the case of hour = 0 that must become 12. That can be done too with calculations, but I didn't want to make the algorithm too complex. But if someone is interested in the math behind that... CODE
Moreover, instead of calling again setTimer() AFTER the chiming, you can just call a llSetTimerEvent(3600) when the timer event has just fired. But in this way, you'll risk getting that lag you feared in your previous post... So, question: how do you turn the clock hands? Cause it can be done like I said in my second post, and avoid lag. |
|
Hg Beeks
llGetElement(80);
Join date: 13 Apr 2006
Posts: 134
|
06-15-2007 00:15
Ok, let's see: instead of setTimer() { integer curTime = (integer)llGetWallclock() - (60 * 60 * ((integer)llGetWallclock() / 60 / 60)); integer timeTilHour = 3600 - curTime; llSetTimerEvent(timeTilHour); } it would be simpler as: setTimer() { integer timeTilHour = 60 * (58 - (integer)llGetSubString(llGetTimestamp(), 14, 15)); //see number of minutes until next hour, then multiply to get seconds llSetTimerEvent(timeTilHour); } while instead of integer temp = ((integer)llGetWallclock() / 60 / 60); you can of course use integer hour = (integer)llGetSubString(llGetTimestamp(), 11, 12) + (time zone); //must compensate for GMT / PST time zone difference... That's right, the problem of the number of chimes is because they all correspond to the hour, except when you need twelve and instead you could have 00 or 12. Not to mention when it will start chiming fifteen times at three PM! So I developed a simple algorithm that can solve that; you'll have to check with an IF for the case of hour = 0 that must become 12. That can be done too with calculations, but I didn't want to make the algorithm too complex. But if someone is interested in the math behind that... CODE
Moreover, instead of calling again setTimer() AFTER the chiming, you can just call a llSetTimerEvent(3600) when the timer event has just fired. But in this way, you'll risk getting that lag you feared in your previous post... So, question: how do you turn the clock hands? Cause it can be done like I said in my second post, and avoid lag. I just checked to see if the hour was greater than 12, and if it was, then it subtracted by 12. I suppose I'd need one for if the hour is 0. Guess I pasted an old version of the code. And all I'm making is the chime, no hands. |
|
Galbraith Karami
Registered User
Join date: 12 Dec 2006
Posts: 25
|
06-15-2007 00:24
Painted clock?
By the way yes, the algorithm or two if lines will work equally fine. If you want to avoid lag, check the hour with the timer event every, say, ten minutes or so, depending on the region average lag. |
|
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
|
06-15-2007 06:12
Only one line of code required to convert your hours into a 12 hour clock time:
hour %= 12; // hour equals the remainder of hour divided by 12. Just remember that 12 o'clock is 0. |