Thread: Using time.h for respawn times?

  1. #1
    Registered User
    Join Date
    Apr 2011

    Lightbulb Using time.h for respawn times?

    I'm making a little text-based RTS and I'm at the point to where I need to start making something to run respawn times. I came across time.h and it looks like I could use it but I guess my mind is wrapping around it easily as I thought it would.

    I just need a basic respawn timer right now that will count how many seconds have passes since the game has started and to give the player 1 citizen for every x amount of seconds of game time.

    Thanks! ;]

    -Oh, I'm programming in C++

  2. #2
    Registered User
    Join Date
    Apr 2011
    I would suggest it for a simple console game!
    Just make a variable and set it to the current time,
    then make a new one when you wanna know the seconds passed, and take away the original game start variable from it.
    would work just fine, not sure how relevant it would be when using other libraries later............

  3. #3
    Registered User
    Join Date
    Apr 2011
    Hmmm, I've been learning how to program for about 2 years now. What would the difference be? I'd be up for it if you can persuade me! ;p

    EDIT: I think I might just use some SDL for this game. It has a timer already in it and it's way simpler to use.
    Last edited by Sheldar; 04-25-2011 at 12:32 AM.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    time.h is complicated but you can get the time since your program started with clock(). This value can be divided by CLOCKS_PER_SEC so that you can see how many seconds have passed. Generally the clock is actually more accurate than once per second, but less accurate than once-per-millisecond. (For historical reasons it may tick 18.2 times per second. Go figure.)

    That said, I highly recommend the SDL. Go try it out! [The SDL's timer is much simpler, it just returns the number of milliseconds, with approximately 10-ms accuracy.]

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. clock and cycle times' effect on counter time?
    By rexnprogress in forum C++ Programming
    Replies: 0
    Last Post: 11-11-2005, 07:16 PM
  2. Times.h
    By LearningC in forum C Programming
    Replies: 6
    Last Post: 10-02-2005, 09:09 AM
  3. time.h: time returns different times
    By odysseus.lost in forum C Programming
    Replies: 3
    Last Post: 05-24-2005, 03:38 AM
  4. Firefox in NY Times
    By Perspective in forum A Brief History of
    Replies: 40
    Last Post: 12-23-2004, 12:42 PM
  5. How many times can time variables be delcared?
    By Qui in forum C++ Programming
    Replies: 2
    Last Post: 04-17-2004, 04:24 PM

Tags for this Thread