Countdown to event
|
|
Xixao Dannunzio
Owner, X3D Enterprises
Join date: 20 Mar 2006
Posts: 114
|
06-19-2006 12:43
I'm in urgent need of a countdown script. I'm flying out to meet my partner in RL on Friday, and she's constantly working out how many days, hours, minutes, and seconds are left until I arrive. I want to surprise her with something that'll do that for her.
Any ideas on how to accomplish this?
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
06-19-2006 13:07
We use a countdown clock I wrote in Limbo to show just that for the Dragon releases. Go have a look sometime. 
|
|
Xixao Dannunzio
Owner, X3D Enterprises
Join date: 20 Mar 2006
Posts: 114
|
06-19-2006 17:44
Any tips on how I should go about creating it? A demo is nice, but doesn't help me much 
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
06-20-2006 08:24
Well, I pointed you there to see if it would meet your needs, as I am willing to sell it.  Otherwise, it is basically a simple countdown clock which uses a texture with all 10 numbers on it and sets the texture offset for each digit as it changes. Nothing too fancy. 
|
|
Xixao Dannunzio
Owner, X3D Enterprises
Join date: 20 Mar 2006
Posts: 114
|
06-20-2006 09:23
If it'll do the job, I'll take it. Not much concerned about looks. It could use llSetText and hover over a wooden box for all I care. Lol. Let me know what you want for it, and I can pay you tonight.
|
|
Keiki Lemieux
I make HUDDLES
Join date: 8 Jul 2005
Posts: 1,490
|
06-20-2006 10:09
Try this: integer expires;
// This function takes 8 arguments, the first six are the date and time. // GMToffset is adjust it based on the timezome. Use -8 for the SL clock. // DST should be TRUE or FALSE depending on daylight savings time. integer MakeUNIXTime( integer year, integer month, integer day, integer hour, integer minute, integer second, integer GMToffset, integer DST ) { list month_days = [ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 ]; integer time = ( year - 1970 ) * 31536000; time += ( day + llList2Integer( month_days, month - 1 ) - 1 ) * 86400; time += ( hour - GMToffset ) * 3600 + minute * 60 + second; if ( DST == TRUE ) { time += -3600; } if ( year > 1972 ) { integer past_leap_years = (integer)( ( year - 1969 ) / 4 ); time += past_leap_years * 86400; } if ( year % 4 == 0 && month > 2 ) { time += 86400; } return time; }
default { state_entry() { // July 1, 2006, 12:15:00 PST/SL Time (see the function above for filling the values for this) expires = MakeUNIXTime( 2006, 7, 1, 12, 15, 0, -8, TRUE ); llSetTimerEvent( 1.0 ); } timer() { integer seconds = expires - llGetUnixTime(); if( seconds > 0 ) { llSetText( (string)seconds + " seconds left", <1.0,1.0,1.0>, 1.0 ); } else { state expired; } } }
state expired { state_entry() { llSetText( "Expired", <1.0,1.0,1.0>, 1.0 ); } } You will need to mess with this line to make it work: expires = MakeUNIXTime( 2006, 7, 1, 12, 15, 0, -8, TRUE ); See the notes in the script to see what the numbers stand for.
_____________________
imakehuddles.com/wordpress/
|
|
Xixao Dannunzio
Owner, X3D Enterprises
Join date: 20 Mar 2006
Posts: 114
|
06-20-2006 10:41
Excellent! Thank you for that  Anyone feel up to the task of modifying this to show days, hours, and minutes left, rather than just seconds? (Keiki earned a cool L$500 for that post, BTW)
|
|
Xixao Dannunzio
Owner, X3D Enterprises
Join date: 20 Mar 2006
Posts: 114
|
06-20-2006 11:40
I stripped apart another script, and modified it to work in this case. Anyone care to double-check it? It seems to be displaying time correctly, but I'm too tired to actually do the math to check its accuracy... string zero_pad(integer number) { if (number < 10) return "0" + (string)number; else return (string)number; }
string format_time(integer seconds) { integer secs = seconds % 60; seconds /= 60; integer mins = seconds % 60; integer hours = seconds / 60; integer hrs = mins % 60; integer days = hours / 24; return (string)days + " days, " + (string)hrs + " hours, " + zero_pad(mins) + " minutes, and " + zero_pad(secs)+" seconds"; }
integer gCountdown;
integer expires;
// This function takes 8 arguments, the first six are the date and time. // GMToffset is adjust it based on the timezome. Use -8 for the SL clock. // DST should be TRUE or FALSE depending on daylight savings time. integer MakeUNIXTime( integer year, integer month, integer day, integer hour, integer minute, integer second, integer GMToffset, integer DST ) { list month_days = [ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 ]; integer time = ( year - 1970 ) * 31536000; time += ( day + llList2Integer( month_days, month - 1 ) - 1 ) * 86400; time += ( hour - GMToffset ) * 3600 + minute * 60 + second; if ( DST == TRUE ) { time += -3600; } if ( year > 1972 ) { integer past_leap_years = (integer)( ( year - 1969 ) / 4 ); time += past_leap_years * 86400; } if ( year % 4 == 0 && month > 2 ) { time += 86400; } return time; }
default { state_entry() { // July 1, 2006, 12:15:00 PST/SL Time (see the function above for filling the values for this) expires = MakeUNIXTime( 2006, 6, 23, 11, 52, 0, -5, TRUE ); llSetTimerEvent( 1.0 ); } timer() { integer seconds = expires - llGetUnixTime(); if( seconds > 0 ) { gCountdown = seconds; llSetText(format_time(--gCountdown)+"\nTil event.", <1.0,1.0,1.0>, 1.0 ); } else { state expired; } } }
state expired { state_entry() { llSetText( "Expired.", <1.0,1.0,1.0>, 1.0 ); } }
:: Edit ::Okay, it's not right. The hours don't compute properly. Instead, they match the number of minutes remaining. Any ideas...?
|
|
Xixao Dannunzio
Owner, X3D Enterprises
Join date: 20 Mar 2006
Posts: 114
|
06-20-2006 11:54
[code removed]
Okay, thought I had it working, but it doesn't like the number of days now. Lol. Anyone?
|
|
Keiki Lemieux
I make HUDDLES
Join date: 8 Jul 2005
Posts: 1,490
|
06-20-2006 19:03
Here you go! integer expires;
// This function takes 8 arguments, the first six are the date and time. // GMToffset is adjust it based on the timezome. Use -8 for the SL clock. // DST should be TRUE or FALSE depending on daylight savings time. integer MakeUNIXTime( integer year, integer month, integer day, integer hour, integer minute, integer second, integer GMToffset, integer DST ) { list month_days = [ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 ]; integer time = ( year - 1970 ) * 31536000; time += ( day + llList2Integer( month_days, month - 1 ) - 1 ) * 86400; time += ( hour - GMToffset ) * 3600 + minute * 60 + second; if ( DST == TRUE ) { time += -3600; } if ( year > 1972 ) { integer past_leap_years = (integer)( ( year - 1969 ) / 4 ); time += past_leap_years * 86400; } if ( year % 4 == 0 && month > 2 ) { time += 86400; } return time; }
default { state_entry() { // July 1, 2006, 12:15:00 PST/SL Time (see the function above for filling the values for this) expires = MakeUNIXTime( 2006, 7, 1, 12, 15, 0, -8, TRUE ); llSetTimerEvent( 1.0 ); } timer() { integer seconds = expires - llGetUnixTime(); if( seconds > 0 ) { integer days = seconds / 86400; integer hours = ( seconds - ( days * 86400 ) ) / 3600; integer minutes = ( seconds - ( days * 86400 ) - ( hours * 3600 ) ) / 60; seconds = ( seconds - ( days * 86400 ) - ( hours * 3600 ) - ( minutes * 60 ) ); string s1 = " days, "; if( days == 1 ) { s1 = " day, "; } string s2 = " hours, "; if ( hours == 1 ) { s2 = " hour, "; } string s3 = " minutes, and "; if ( minutes == 1 ) { s3 = " minute, and "; } string s4 = " seconds left"; if ( seconds == 1 ) { s4 = " second left"; } llSetText( (string)days + s1 + (string)hours + s2 + (string)minutes + s3 + (string)seconds + s4, <1.0,1.0,1.0>, 1.0 ); } else { state expired; } } }
state expired { state_entry() { llSetText( "Expired", <1.0,1.0,1.0>, 1.0 ); } }
_____________________
imakehuddles.com/wordpress/
|
|
Xixao Dannunzio
Owner, X3D Enterprises
Join date: 20 Mar 2006
Posts: 114
|
06-20-2006 21:34
Works perfectly  Another L$500 for Keiki!
|