Is it possible to use the time.h to do this?

Alright so basically I want to know if it's possible to do something in the lines of:

Get the current seconds "time_t seconds;".
Compare it with a new value that's something like "newValue = seconds + 20;

Then check if newValue > seconds do nothing.
Else once that time runs out. Display that seconds has overlaped newValue.

Might sound a little weird in this example with time.h but I want to be able to use something that checks like the above so I can use other functions during the wait for the timer.
I don't complelty understand what you want, but maybe I can help:

so I can use other functions during the wait for the timer.


How about this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <windows.h>
#include <time.h>

void printValue(int number)
{
    system("cls");
    std::cout<<number;
}

int main()
{
    int i=0;
    while (true)
    {
        i++;
        clock_t end=clock()+1000;
        while (clock()<end)
        {
            if (GetAsyncKeyState(VK_SPACE))
                printValue(i); //function call in the wait for timer
        }
    }
    return 0;
}
Well for the situation I was going to use it in would be. I have a main character controlled by a player. Then there is ai for computer players. Now what these computer players do is basically come running at you all the time as soon as they see you. What I want to happen is: When they do see you they have a countdown happen for the AI that makes them wait etc 10 seconds before they come chasing you. So during every loop it checks the amount of seconds they AI has left before they are allowed to start running.

Does that make a bit more sense?
Yes, now I see what you want :)

I would make the time of seconds since they've seen you a membervariable of your AI and create a memberfunction "live()" or something like that to control all the actions from the AI. Does the countdown need to be started? Should the AI move? Attack? etc.
Then you can call that memberfunction inside the while (clock()<end) loop for every AI on the screen, and you can use if (GetAsyncKeyState(SOME_KEY) statements (inside the while-loop) to control your character.
Topic archived. No new replies allowed.