Trying to make a time system for a game

Jan 3, 2012 at 8:08pm
I'm trying to figure out how to create a time system for a video game, but the ctime reference is garbage for somebody who has never toutched that library before. can somebody point me in the right direction.

i just need the time system to do two things: (1) present the hour:minute and the month, day, year to the player. (2) present the player with how many hours since he started a new game.
Jan 4, 2012 at 10:26am
Jan 4, 2012 at 11:00am
Thanks for the link.
Jan 4, 2012 at 10:43pm
i dont want links for this site, i find them useless because this is a library i have never used. i need to have the library explained a little better.

the only thing i understand is the time data structure
Jan 4, 2012 at 11:22pm
(1) present the hour:minute and the month, day, year to the player.


Here is how to present the date and time. What don't you understand in it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* localtime example */
#include <stdio.h>
#include <time.h>

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  printf ( "Current local time and date: %s", asctime (timeinfo) );
  
  return 0;
}
Jan 4, 2012 at 11:23pm
this is a library i have never used
RTFM.
i need to have the library explained a little better.
Fine, ¿what you don't get?
Jan 4, 2012 at 11:29pm
Moschops thank you this is helping me. So rawtime is a variable of data type time_t? and what does the time() function do? timeinfo is a reference to the data structure tm which then equals the function localtime?

me555 i would appreciate it if you only posted useful information.
Jan 4, 2012 at 11:52pm
timeinfo is a reference to the data structure tm which then equals the function localtime

No, timeinfo is a pointer to an object of type tm which is then made equal to the value returned by the function localtime.

If that's all new to you, you're trying to do something far beyond your ability and need to go to basics.
Last edited on Jan 4, 2012 at 11:56pm
Jan 5, 2012 at 12:35am
man wrote:
time - get time in seconds
time_t time(time_t *t);
time() returns the time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
If t is non-NULL, the return value is also stored in the memory pointed to by t.

¿See? beautiful.
Last edited on Jan 5, 2012 at 12:37am
Jan 5, 2012 at 1:01am
i know the basics, the problem is that there is no are between basics and this. or at least i cannot find it anywhere.
Topic archived. No new replies allowed.