ExecuteNext

Started by
1 comment, last by waheyluggage 19 years, 5 months ago
Hi Again! I'm implementing a system with the scripts so I can have a script like... void Go( ) { while (true) { Game_PlayAnim( 3 ); Game_PlaySection( 1 ); Game_PlayAnim( 2 ); } } I use ExecuteStep(asEXEC_STEP_INTO) but it doesn't seem to execute one step of the script, instead it does all of it. Any ideas? My plan is to call my Script_Update function to update a single line of a script. I'll have a script function like BeginSection() and that'll force the script to run until it reaches an EndSection() call. Say I have 3 or 4 scripts doing this - will I need to call Prepare before reusing the context? thanks Scott
Advertisement
With the default compilation of the library, ExecuteStep() only stops once per loop iteration. But if you compile the library with the preprocessor variable BUILD_WITH_LINE_CUES defined, the script compiler will add extra bytecodes that will make ExecuteStep() suspend after each statement. (These preprocessor variables are described in as_config.h)

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:

// C++void Suspend(){  asIScriptContext *ctx = asGetActiveContext();  if( ctx ) ctx->Suspend();}


Then you can have the script writer choose the exact steps simply by calling this function.

// AngelScriptvoid Go(){  while( true )  {    Game_PlayAnim(3); Suspend();    Game_PlaySection(1); Suspend();    Game_PlayAnim(2); Suspend();  }}


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:

// C++void ExecuteScripts(asIScriptEngine *engine){  asIScriptContext *ctx1, *ctx2, *ctx3;  // Create the contexts  engine->CreateContext(&ctx1);   engine->CreateContext(&ctx2);  engine->CreateContext(&ctx3);  // 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 )  {    ctx1->Execute();    ctx2->Execute();    ctx3->Execute();  }}


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.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Hi

I switched to the way you recommended. It let me put a timer in so I can now have it execute a line and then wait for a script defined amount of time.

Works great. Thanks


Scott

This topic is closed to new replies.

Advertisement