You indeed don't need a timer for that. Though if you are still interested here is a little example for the timer.
This script shows 2 timers in one.
Header
class MyTimerScript : public ScriptImpClass
{
void Created(GameObject *obj);
//'GameObject *obj' is the gameobject the script runs on
void Timer_Expired(GameObject *obj, int number);
//obj see above
//'int number' takes an int value that you can use to check which timer ended.
};
CPP
#include "engine.h"
#include "scripts.h"
#include "MyTimerScript.h"
void MyTimerScript::Created(GameObject *obj)
{
Commands->Start_Timer(obj, this, 10.0f, 1);
//param 1 (obj) = object to run the timer on
//param 2 (this) = a ScriptImpClass class or sub-class (in the header you extended ScriptImpClass so 'this' is a sub-class)
//param 3 (10.0f) = time in seconds before the timer expires
//param 4 (1) = number used to check which timer ended (timer ID)
Commands->Start_Timer(obj, this, 20.0f, 2);
//param 1 (obj) = see above
//param 2 (this) = see above
//param 3 (20.0f) = see above
//param 4 (2) = see above (number is now 2 so this timer ID is different from the previous one)
}
void MyTimerScript::Timer_Expired(GameObject *obj, int number)
{
if(number == 1) //if timer with number (ID) 1 ended (the 10 second timer)
{
//Do stuff
}
else if(number == 2) //else, if timer with number (ID) 2 ended (the 20 second timer)
{
//Do other stuff
}
}
I hope this clears thing up. And you dont have to make scripts in existing CPP or H files. You can add your own. Making your own and adding the above code should work immediately (if you name the header file 'MyTimerScript.h' in this case)
[Updated on: Wed, 11 August 2010 03:00]
Report message to a moderator