|
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
|
08-17-2008 07:13
I am having trouble with elapsed time checker. I know the script is inelegant but I am using this to get my head round time stamps. The problem I have is that every 5 or 6 iterations of the timer I get a silent fail and the script just stops. This sometimes happens when I manually reset as well, I'm guessing it's due to my scrappy coding...any ideas? string elapsed(string sTime) { if (sTime == "" ) { sTime = llGetTimestamp(); } else { string sH; string sM; string sS; string sTimeEnd = llGetTimestamp(); integer iHour = (integer)llGetSubString( sTimeEnd, 11, 12 ); integer iMin = (integer)llGetSubString( sTimeEnd, 14, 15 ); float fSec = (float)llGetSubString( sTimeEnd, 17, 22 ); integer iHour_start = (integer)llGetSubString( sTime, 11, 12 ); integer iMin_start = (integer)llGetSubString( sTime, 14, 15 ); float fSec_start = (float)llGetSubString( sTime, 17, 22 ); if (iHour < iHour_start) { iHour += 24; } if (iMin < iMin_start) { iMin += 60; } if (fSec < fSec_start) { fSec += 60.0; }
iHour = iHour - iHour_start; iMin = iMin - iMin_start; fSec = fSec - fSec_start;
if (iHour < 10) { sH = "0"; } if (iMin < 10) { sM = "0"; } if (fSec < 10.0) { sS = "0"; } sTime = sH + (string)iHour + ":" + sM + (string)iMin + ":" + sS + (string)fSec; } return sTime; }
string sStart; integer iMin_elapsed = 0; float fSec_elapsed = 0; list time_start = [];
default{ state_entry() { llSetTimerEvent(9.0); string sStart = elapsed(""); time_start = [sStart]; llSay(0, sStart); } timer() { sStart = llList2String(time_start,0); string sElapsed = elapsed(sStart); integer iMin_elapsed = (integer)llGetSubString( sElapsed, 3, 4 ); integer fSec_elapsed = (integer)llGetSubString( sElapsed, 6, 7 ); if (fSec_elapsed <= 20.0 && iMin_elapsed < 1) { llSay(0,"Sec = " + (string)fSec_elapsed); llSay(0, "Min = "+ (string)iMin_elapsed); llSay(0, sElapsed); llSay(0, "Keep Going"); } else if (fSec_elapsed > 20.0 && iMin_elapsed < 1) { llSay(0, sElapsed); llSay(0,"Sec = " + (string)fSec_elapsed); llSay(0, "Min = "+ (string)iMin_elapsed); llSay(0, "Stop and transfer"); llResetScript(); } } }
_____________________
Tread softly upon the Earth for you walk on my face.
|
|
Cheree Bury
ChereeMotion Owner
Join date: 6 Jun 2007
Posts: 666
|
08-17-2008 08:57
I do not understand why you are checking for elapsed seconds and elapsed minutes. I would start by removing the check on the number of minutes being less than 1.
If you are just trying to figure out timestamps, you pretty well understand them except doing math on timestamps is a bad idea. You have to keep adjusting for changes in minutes, hours, and days, months, and years.
You really need to use llGetUnixTime which only deals in seconds. Get it when the routine starts and keep getting it again until the difference is greater than 20. Then you are done.
If you need an elapsed time display, you can calculate the days, hours, minutes, and seconds yourself fairly easily.
_____________________
Visit ChereeMotion - Life's Best Pinup Poses http://slurl.com/secondlife/Wild%20Rice/38/230/51
|
|
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
|
08-17-2008 09:12
Thanks for your reply Cheree.
This script is only a test of a concept. I was using the minutes and seconds to short cut a much longer time elapsed check. The eventual script will work over days and weeks but I wanted the capacity to check down to the accuracy of seconds.
I also wanted the ability to check dates and times over that period so time stamp seemed to be the way forward but I appreciate your comments about llGetUnixTime.
However it does not explain why the script fails after a few repeats of the timer, that's the bit that is baffling me rather than how to get the time elapsed.
_____________________
Tread softly upon the Earth for you walk on my face.
|
|
Cheree Bury
ChereeMotion Owner
Join date: 6 Jun 2007
Posts: 666
|
08-17-2008 14:20
You still have some logic problems. You are handling where it is less than 1 minute but what if iMin_elapsed equals 1? The following is better, but it still isn't quite right so I added an Error section to show you: timer() { sStart = llList2String(time_start,0); string sElapsed = elapsed(sStart); integer iMin_elapsed = (integer)llGetSubString( sElapsed, 3, 4 ); integer fSec_elapsed = (integer)llGetSubString( sElapsed, 6, 7 ); if (fSec_elapsed <= 20.0 && iMin_elapsed < 1) { llSay(0,"Sec = " + (string)fSec_elapsed); llSay(0, "Min = "+ (string)iMin_elapsed); llSay(0, sElapsed); llSay(0, "Keep Going"); } else if (fSec_elapsed > 20.0 && iMin_elapsed <= 1) { llSay(0, sElapsed); llSay(0,"Sec = " + (string)fSec_elapsed); llSay(0, "Min = "+ (string)iMin_elapsed); llSay(0, "Stop and transfer"); llResetScript(); } else { llSay(0,"Sec = " + (string)fSec_elapsed); llSay(0, "Min = "+ (string)iMin_elapsed); llSay(0, sElapsed); llSay(0, "Error"); } }
The problem is that it fails when it goes from one minute to the next. If you fix that, it is going to fail when it goes from one hour to the next. Then if you fix that, it will fail when it goes from one day to the next.
_____________________
Visit ChereeMotion - Life's Best Pinup Poses http://slurl.com/secondlife/Wild%20Rice/38/230/51
|
|
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
|
08-18-2008 02:10
Of course!
/me palms forhead
Thanks Cheree, that makes sense to me now. The logic stuff I had butchered for a quick test and had not considered what would happen if the elapsed time increased beyond 1 minute although I thought I had got a reset before it passed a minute. Ho hum I'll keep playing.
_____________________
Tread softly upon the Earth for you walk on my face.
|