Members - Reputation: 122
Posted 23 November 2004 - 07:46 AM
Moderators - Reputation: 4362
Posted 23 November 2004 - 08:17 AM
I don't recommend doing it this way though, as neither the application nor the script writer have much control over how much is executed with each step.
Instead I recommend that you register a function like this:
asIScriptContext *ctx = asGetActiveContext();
if( ctx ) ctx->Suspend();
Then you can have the script writer choose the exact steps simply by calling this function.
while( true )
Using this way, you would ideally use Execute() instead of ExecuteStep(), as the execution would only be suspended where the script writer explicitly chose to.
If you plan on having long going functions like these running in parallell, you need to create one context for each of them. The Prepare() function should only be called once to prepare the context stack. Example:
void ExecuteScripts(asIScriptEngine *engine)
asIScriptContext *ctx1, *ctx2, *ctx3;
// Create the contexts
// Prepare the contexts once
ctx1->Prepare(engine->GetFunctionIDByDecl(0, "void func1()"));
ctx2->Prepare(engine->GetFunctionIDByDecl(0, "void func2()"));
ctx3->Prepare(engine->GetFunctionIDByDecl(0, "void func3()"));
// Execute in a round-robin fashion
while( true )
You'll need to verify the return code for Execute() so that you can handle premature termination of the script code, for example by script exception.
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game