I love the feeling when you actually solve something on your own! What I was able to figure out was this:
The addTimer function would stuff inside a structure data it's name, time, and function to be called. Here's slight code and if you ever want to use it - go ahead.
AngelScript
void onStart() {
addTimer("timer",5.0f,"timer_funct");
}
void timer_funct() {
//--- DO whatever you want to do after timer has reached.
}
C++ code:
struct Timer {
std::string Name;
float time;
std::string FunctionCallback;
bool complete;
};
std::vector<Timer> timers;
unsigned long startTime;
unsigned long elapsedTime;
void startTimer() {
startTime = clock();
}
float getElapsedTime() {
return(((float) clock() - startTime) / CLOCKS_PER_SECOND);
}
void addTimer(std::string &name, float time, std::string &functcallback) {
Timer time = { name, time, functcallback, false };
timers.push_back(time);
}
//-- This is for constantly checking to see when timer is finished.
void checkTimers() {
if(!Timers[0].complete) {
if(getElapsedTime() >= Timers[0].time) {
Timers[0].complete = true;
asIScriptContext *ctx = engine->CreateContext(); //-- as said in the documentation it's better to have the original script context.
std::string funcdecl = "void " + Timers[0].FunctionCallback + "()";
asIScriptFunction *func = ctx->GetModule(your module name here")->GetFunctionByDecl(functdecl);
if(funct != null) {
ctx->Prepare(func);
int r = ctx->Execute();
if(r == asEXECUTE_FINISHED) {
}
}
}
}
}
the checkTimers function should be in the render loop and the startTimer() should be in the initialization of the game of course.
Some of the functions I tried to memorize may be a bit off on function calls. However, essentially what's it's doing is checking to see if the timer is reached elapse point then going back and calling a function declared inside the script file.
There's probably a better way of going about all this of course.