displaying time left of a timer

Posted by Feantur on Fri 27 Aug 2004 08:21 AM — 11 posts, 37,894 views.

#0
Is there a way to display the time left of a timer somewhere? E.g. like a countdown?
USA #1
http://www.gammon.com.au/scripts/function.php?name=GetTimerInfo

You can get it a few ways, your best bet is 13 though (although if youre into masochism, you could get the timer length, and the time it last was reset and also check the "at" flag).
#2
I've tried to set it up, unfortunately it only sends to the MUD screen itself. It would be nice to have something like the counter that shows how long I had the world open, just doing a count down instead of a count up (with automatical resets etc.).
Australia Forum Administrator #3
If you want a constant update like that, you would need a second timer (eg. every second) that checks the first timer using what was suggested above (GetTimerInfo selector 13).

It could then use SetStatus to update the status bar at the bottom of the screen.
#4
My timer does the following atm:

world.SetStatus( "idle: " + (((600 - world.GetTimerInfo ("idle", 13))/60) + ":" + (600 - world.GetTimerInfo ("idle", 13))%60) );

This displays e.g. as follows:

idle: 8.5:35

What I'd like it to do is drop the .5 part and only display the integer part of the first call to GetTimerInfo. I've tried using Math.round - while it doesn't create an error it also doesn't deliver the result I'd expect.

Also tried CInt, which isn't recognised.
Amended on Sat 18 Dec 2004 07:28 AM by Feantur
USA #5
You could either subtract .5 from it then round, or use the floor function.

Floor will cause problems at negative values (well, not problems, but most people think intuitively that it will act like ceil does). Actually... both subtracting .5 and floor produce the same thing.

Edit: and Cint is VB, and thats converting from strings.
Amended on Sat 18 Dec 2004 07:32 AM by Flannel
#6
Funnily the JScript help returned CInt as convert-to-integer method (at a second glance I saw the help file is actually on all of Microsoft's scripting languages).

Can't subtract .5 because it's not a constant bit. It changes through various values, as in parts of a minute.

Trying the floor method next.
USA #7
No. Subtract one half, and then round.

3.5 becomes 3 (rounds to 3)
3.9 becomes 3.4 (rounds to 3)
3.0 becomes 2.5 (rounds to 3)

And if you look at the VERY top of the windows scrip file, it will tell you which section youre in. (VB or JS, etc)
#8
Ok, this is a very crude way to do it probably, but it works now:

if (Math.round((((600 - world.GetTimerInfo ("idle", 13))/60)-0.5)) < 10)
{
if (((600 - world.GetTimerInfo ("idle", 13)) %60) < 10)
world.SetStatus( "idle: 0" + ( Math.round( ((600 - world.GetTimerInfo ("idle", 13))/60)-0.5 ) + ":" + "0" + (600 - world.GetTimerInfo ("idle", 13))%60) );
else
world.SetStatus( "idle: 0" + ( Math.round( ((600 - world.GetTimerInfo ("idle", 13))/60)-0.5 ) + ":" + (600 - world.GetTimerInfo ("idle", 13))%60) );
}
else
world.SetStatus( "idle: " + ( Math.round( ((600 - world.GetTimerInfo ("idle", 13))/60)-0.5 ) + ":" + (600 - world.GetTimerInfo ("idle", 13))%60) );

Any suggestions for improvement?
USA #9
What are you trying to do with that? Keep it from going to one digit?
#10
It displays how long I'm idle so far (output is "idle: 05:32" etc., counting upwards) - the ifs and elses only add leading zeros in case they are needed for cosmetical reasons.