Server Help

Bot Questions - Display ticker time format - Merv

Anonymous - Mon Aug 13, 2007 8:34 pm
Post subject: Display ticker time format - Merv
MervBot

How could I display the ticker in time format 6:52 instead of 391 sec's.

In JS Id do something like this but.. this aint JS

Code: Show/Hide

function convetToTime()
{
   var _time = 391/60;
   var _roundtime = Math.round(100*_time)/100;     
    var _outputtime = _roundtime.toString().replace(".", ":");
   
   alert(_time + " : "  + _roundtime + " : " +  _outputtime);
}



Thanks
CypherJF - Mon Aug 13, 2007 9:03 pm
Post subject:
This is something I've reused from Catid -

Code: Show/Hide

String botInfo::RunningTime2(unsigned int start_time, unsigned int end_time)
{
    String gt;
       uint flagGameTime = end_time- start_time;
      gt = getString(flagGameTime / 3600, 10, 2, true);
      gt += "h ";
      gt += getString((flagGameTime / 60) % 60, 10, 2, true);
      gt += "m ";
      gt += getString(flagGameTime % 60, 10, 2, true);
      gt += "s";
   return gt;
}

Anonymous - Mon Aug 13, 2007 10:18 pm
Post subject:
Thanks for the quick reply CypherJF, It worked perfectly!!


BugZap
D1st0rt - Mon Aug 13, 2007 11:43 pm
Post subject:
I tried to implement this for hyperspace racing using ctime but it wanted to do everything from the Unix epoch or something and came out weird, so it's not as pretty:

Code: Show/Hide
#define TIMEBUFFERSIZE 12
char *timeString(long time, char *buffer)
{
   int minutes;
   int seconds;
   int millis;

   minutes = (time - (time % 60000)) / 60000;
   seconds = ((time - (minutes * 60000)) - ((time - (minutes * 60000)) % 1000)) / 1000;
   millis = (time - (minutes * 60000) - (seconds * 1000));

   snprintf(buffer, TIMEBUFFERSIZE-1, "%01d:%02d.%03d", minutes, seconds, millis);
   buffer[TIMEBUFFERSIZE-1] = 0;

   return buffer;
}

usage is something like this (not tested)
Code: Show/Hide
char formatted[TIMEBUFFERSIZE];
long time = 60000; //1 minute
timeString(time, formatted);
printf("Time: %s" + formatted);


ok gurus, time to tell me how this could be done better (I think the return is only still in there for legacy code)
Samapico - Tue Aug 14, 2007 12:15 am
Post subject:
I'm no guru but...
Code: Show/Hide
int millis;
int seconds;
int minutes;

millis = time % 1000;
time /= 1000;
seconds = time % 60;
minutes = time / 60;

...
?
Anonymous - Tue Aug 14, 2007 3:45 am
Post subject:
I just wish I could switch a integer to string and back more easily in C.
In JS you can just toString() a number or even more lame like someinteger+="" and its now a string..


Anyway, Thanks again that code from Catid also makes it easy to trim unneeded digits, so that 3:47 isnt displayed 03:47 etc.
Maverick - Tue Aug 14, 2007 6:09 am
Post subject:
Use Java, it can be compared to Javascript in code syntax (although both are completely different). tongue.gif
Samapico - Tue Aug 14, 2007 10:12 am
Post subject:
with Merv, I simply use the String class that is built in it...

Code: Show/Hide

String timestring(long time)
{
int millis = time % 1000;
time /= 1000;
int seconds = time % 60;
int minutes = time / 60;

String s = (String)minutes + ":" + (String)seconds;

return s;
}

Cyan~Fire - Tue Aug 14, 2007 10:20 am
Post subject:
BugZap wrote:
I just wish I could switch a integer to string and back more easily in C.

Because C/C++ actually let you know how expensive an operation is. If it's hard for you, it's probably hard for the computer. icon_smile.gif
Anonymous - Tue Aug 14, 2007 2:35 pm
Post subject:
String s = (String)minutes, I frogot about that... lol
CypherJF - Tue Aug 14, 2007 5:12 pm
Post subject:
BugZap wrote:
Thanks for the quick reply CypherJF, It worked perfectly!!


BugZap


Your welcome, it's only because I've had to use that code a few times before, and the external HD which has all my source code is plugged in right now. icon_smile.gif
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group