Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

countdown timer

Yamil Dagger
Registered User
Join date: 10 Jul 2007
Posts: 36
05-12-2008 15:21
Can anybody tell me a good way to do a countdown timer to ensure it's counting 1 every second? Right now I have it all setup with the timer event set to 1 so it should be counting 1 every second but it seems too slow. I set the timer event to 0.1 and it counted at the same speed for some reason.

Can anybody think of a better way of doing it? I was thinking of reading the wallclock time and setting the "difference" but then at midnight it would screw up... so i don't think that will work.

Anybody?
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
05-12-2008 16:28
what procces you using? keep in mind some stuff has a delay
Yamil Dagger
Registered User
Join date: 10 Jul 2007
Posts: 36
05-12-2008 21:32
Here's the script I'm using. It sends the updated time to an XYtext object (visually shows the time without using hovertext)

------------------------------------------------------
string zero_pad(integer number)
{
if (number < 10) return "0" + (string)number;
else return (string)number;
}

string format_time(integer seconds)
{
integer days = llFloor(seconds / 86400);
seconds -= days * 86400;
integer hours = llFloor(seconds / 3600);
seconds -= hours * 3600;
integer minutes = llFloor(seconds / 60);
seconds -= minutes * 60;
return (string)days+":" +zero_pad(hours) + ":" + zero_pad(minutes) + ":" + zero_pad(seconds);
}

integer gCountdown = 0; //863999
integer settingsline = 0;
key settingsID;
string temp1;
string temp2;
list time1;
list time2;
integer seconds1;
integer seconds2;
integer startup = FALSE;
integer switch = 0;

default
{
state_entry()
{
startup = TRUE;
llMessageLinked(LINK_SET, 100110, "0:00:00:00", "";);
settingsID = llGetNotecardLine("Settings", 1);
}

touch(integer times)
{
settingsID = llGetNotecardLine("Settings", 1);
}

timer()
{
if (gCountdown > 0)
llMessageLinked(LINK_ALL_OTHERS, 100110, format_time(--gCountdown), "";);
else
llMessageLinked(LINK_ALL_OTHERS, 100110, "0:00:00:00", "";);
if (gCountdown == 0)
{
if (switch == 0)
{
if (seconds2 > 0)
gCountdown = seconds2;
switch = 1;
return;
}
if (switch == 1)
{
if (seconds1 > 0)
gCountdown = seconds1;
switch = 0;
return;
}
}
}

dataserver(key query_id, string data)
{
if (query_id == settingsID) if (data != EOF)
{
if (settingsline == 1)
{
temp1 = (string)data;
time1 = llParseString2List(temp1,[":"],[""]);
seconds1 += (llList2Integer(time1,0)*86400); //days
seconds1 += (llList2Integer(time1,1)*3600); //hours
seconds1 += (llList2Integer(time1,2)*60); //minutes
seconds1 += llList2Integer(time1,3); //seconds
settingsline = 3;
}
if (settingsline == 4)
{
temp2 = (string)data;
time2 = llParseString2List(temp2,[":"],[""]);
seconds2 += (llList2Integer(time2,0)*86400); //days
seconds2 += (llList2Integer(time2,1)*3600); //hours
seconds2 += (llList2Integer(time2,2)*60); //minutes
seconds2 += llList2Integer(time2,3); //seconds
llOwnerSay("New times are now set.\nChange the times on the settings page then touch me to set new times.";);
if (startup == TRUE)
{
switch = 0;
gCountdown = seconds1;
llSetTimerEvent(1);
startup = FALSE;
}
data = EOF;
}
++settingsline;
settingsID = llGetNotecardLine("Settings", settingsline);
}
}
}
--------------------------



This countdown timer reads two times from the settings page. then counts down the first, then counts down the second, then starts on the first again...ect.
Zolen Giano
Free the Shmeats!
Join date: 31 Dec 2007
Posts: 146
05-12-2008 22:20
I'm thinking that the script is unable to complete an iteration once a second.

You're doing quite a bit of procesing there, but I think the big hit on your performance is sending linked messages to every prim in the xyText object cuz they're alot of prims.

From the Wiki:
"There is no delay on any of the llMessageLinked, llSay, llWhisper, or llShout functions. The "delay" is in the event queuing for the receiving event, which is affected by the sims performance at that given time."

So, if you're doing a few hundred link message events per second, you might notice some lag in your script. How many prims in an xytext?

You might be able to send the linked message to another script sperate from your timer that repeats it to xyText to avoid a delay in the original script.
Yamil Dagger
Registered User
Join date: 10 Jul 2007
Posts: 36
05-13-2008 05:48
well in my test i was using one xytext object (displays 10 letters) with the backboard as the root prim for a grand total of 2 prims. I took it elseware and it ran perfectly, once per second like it should. So since the sim itself obviously can effect it, I need a better way of doing this to ensure it doesn't get off time.
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
05-13-2008 17:22
Use llGetUnixTime() - http://lslwiki.net/lslwiki/wakka.php?wakka=llGetUnixTime

When the countdown begins, calculate the final second. On each timer event, subtract the current time from the final time and display the result. This will be accurate, but could skip numbers if the server lags.

From: someone
integer SECS_TO_COUNT = 30;
integer stop;

default {
touch_start(integer num) {
stop = llGetUnixTime() + SECS_TO_COUNT;
llSetTimerEvent(1.0);
}
timer() {
integer current_sec = stop - llGetUnixTime();
if (current_sec > 0) {
// update display
}
else {
// all done, display zero, stop timer
}
}
}