Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Display ticker time format - Merv

 
Post new topic   Reply to topic Printable version
 View previous topic  Buybot Post :: Post Duel.ini  View next topic  
Author Message
BugZap
Guest


Offline

PostPosted: Mon Aug 13, 2007 8:34 pm    Post subject: Display ticker time format - Merv Reply to topic Reply with quote

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
Back to top
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Mon Aug 13, 2007 9:03 pm    Post subject: Reply to topic Reply with quote

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;
}

_________________
Performance is often the art of cheating carefully. - James Gosling
Back to top
View users profile Send private message Add User to Ignore List
BugZap
Guest


Offline

PostPosted: Mon Aug 13, 2007 10:18 pm    Post subject: Reply to topic Reply with quote

Thanks for the quick reply CypherJF, It worked perfectly!!


BugZap
Back to top
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Mon Aug 13, 2007 11:43 pm    Post subject: Reply to topic Reply with quote

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)
_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Tue Aug 14, 2007 12:15 am    Post subject: Reply to topic Reply with quote

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;

...
?
_________________
(Insert a bunch of dead links here)
Back to top
View users profile Send private message Add User to Ignore List
BugZap
Guest


Offline

PostPosted: Tue Aug 14, 2007 3:45 am    Post subject: Reply to topic Reply with quote

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.
Back to top
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Tue Aug 14, 2007 6:09 am    Post subject: Reply to topic Reply with quote

Use Java, it can be compared to Javascript in code syntax (although both are completely different). tongue.gif
_________________
Nickname: Maverick (I changed my name!)
TWCore developer | Subspace statistics
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Tue Aug 14, 2007 10:12 am    Post subject: Reply to topic Reply with quote

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;
}
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Tue Aug 14, 2007 10:20 am    Post subject: Reply to topic Reply with quote

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
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
BugZap
Guest


Offline

PostPosted: Tue Aug 14, 2007 2:35 pm    Post subject: Reply to topic Reply with quote

String s = (String)minutes, I frogot about that... lol
Back to top
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Tue Aug 14, 2007 5:12 pm    Post subject: Reply to topic Reply with quote

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
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 22 page(s) served in previous 5 minutes.

phpBB Created this page in 0.458232 seconds : 35 queries executed (92.5%): GZIP compression disabled