Page 1 of 1

How do turn Itimer

Posted: Sat Mar 18, 2006 3:29 pm
by Willikus
So... I seek but I do not find an explanation simple...

ITimer the time functiun !

How make a clock (10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0!!!! Explosion for exemple)

In FPS, I try to use SetTime(x?) when I puch 'P', but when I puch 'P', my camera go in the place of x? seconde ago... (return towards the past)
How turn SetTime() ?
------------
timer->start();/stop();

What use this function...

The rest if is importante
__________________________
So, the context of my application :


I puch 'P',

If (Gv==0){
Gv =1

Gravity = -1
(Clock : 5,4,3,2,1,0!!!)
Gravity = 1

Gv=0
}


Help me, thx

Posted: Sat Mar 18, 2006 4:28 pm
by killzone721
if i understand your question, then what you want is to start a timer...


well i have made class timer for myself to deal with timer... maybe this might hep

Code: Select all


class Timer
{
public:
	void declare()
	{
     irrTimer = mainmenu->getTimer();
	 irrTimer->getTime();
    }
	void set(int timeout)
	{
	 beginTime = irrTimer->getTime();
	 interval=0;
	 interval = timeout;
    }
	void start()
	{
     beginTime = irrTimer->getTime();
	 interval = 0;
    }
	bool alarm()
	{
	 int now = irrTimer->getTime();
     if((now - beginTime)>=interval)
     {
      return true;
     }
     else{return false;}
     return true;
    }
	int stop()
	{
	 int now = irrTimer->getTime();
	 interval = (now-beginTime);
	 return interval;
    }
	int check()
	{
	 int now = irrTimer->getTime();
	 interval = (now-beginTime);
	 return interval;
    }
	void reset()
    {
	 beginTime = 0;
	 interval = 0;
    }
private:
    int beginTime;
	int interval;
	ITimer* irrTimer;
};
to use this timer class make sure you call variable.declare(); first or the game will crash

HOPE THIS HELPS! :wink:

Posted: Sat Mar 18, 2006 8:45 pm
by Willikus
Thx for your answerd !

I go try your code (I must changed the HHD :? )

So... during the small time between the question and your answerd, I try other code but his stop all games during 2 seconde...

I don't tell my life and I go try... :arrow:

Posted: Sat Mar 18, 2006 10:52 pm
by killzone721
i updated the class a bit

SO USE THIS ONE INSTED OF THE ONE ABOVE... THIS CLASS HAS THE AME CONCEPT THOUGH

Code: Select all

class Timer
{
public:
   void declare()
   {
     irrTimer = mainmenu->getTimer();
    irrTimer->getTime();
    }
   void set(int timeout)
   {
    beginTime = irrTimer->getTime();
    interval=0;
    interval = timeout;
    }
   void start()
   {
     beginTime = irrTimer->getTime();
    interval = 0;
    }
   bool alarm()
   {
    int now = irrTimer->getTime();
     if((now - beginTime)>=interval)
     {
      return true;
     }
     else{return false;}
    }
   int stop()
   {
    int now = irrTimer->getTime();
    interval = (now-beginTime);
    return interval;
    }
   int check()
   {
    int now = irrTimer->getTime();
    interval = (now-beginTime);
    return interval;
    }
   void reset()
    {
    beginTime = 0;
    interval = 0;
    }
private:
    int beginTime;
   int interval;
   ITimer* irrTimer;
}; 

Posted: Sun Mar 19, 2006 8:53 am
by Willikus
Ok!

I'm french and I don't understand english very well (and the code). :oops:
So, You confirm my said:

->This code replace the ITimer (start(), stop(), ...) ?!
->This code add alarm() (and other but I don't know) ?!
->For regulate the Timer, I must modify 'interval' ???

And if you can confirm : if this functiun can use like this :
__________________________________________________
...Puch P...
if (alarm() == 0){
irrTimer->start();

Gravity = -1

if(alarm() == 1){ //<= It's possible ?
Gravity = 1
irrTimer->stop();
irrTimer->reset();
} else {
}
___________________________________________________

I'm sorry for ask question on C++

W

Posted: Sun Mar 19, 2006 2:00 pm
by killzone721
Not exactly


Code: Select all


Timer timer                               //make a variable of the class timer

timer.declare();                         // you have to do this first or it will crash
timer.set(1000);               //you set the time 1000 = 1 sec ... it goes in 1000s
timer.stop();         // stop the timer because we have to do something before
Gravity = 1;            // START THE JUMP
timer.start();          //NOW START THE TIMER
if(timer.alarm()==true) // if timer done then
{
   gravity = -1;    //PUT GTRAVITY BACK ON
}

/////////////////////////DONE ///////////////////////////////////////

hop this helps and don't worry.. ask as many questions as you want

Posted: Sun Mar 19, 2006 2:03 pm
by killzone721
last post might be too UNCLEAR :D

here the code without documentation

Code: Select all


Timer timer 

timer.declare();
timer.set(1000);
timer.stop();  
Gravity = 1; 
timer.start();
if(timer.alarm()==true) 
{
   Gravity = -1;   
} 


HOPE THIS HELPS :wink: 

Posted: Thu Mar 23, 2006 1:23 pm
by andrei25ni
killzone721, I have tryed your code, but I get this error :

295 MainMenu.cpp `timer' does not name a type
296 MainMenu.cpp `timer' undeclared (first use this function)

Do you know what I'm doing wrong ?