Update script function argument on resume from suspend

Started by
1 comment, last by iraxef 10 years, 4 months ago

If I Suspend() a currently-running script and on the next engine tick I update the arguments and call Execute() on that context, I'm not seeing the arguments update.

This is what I'm trying to do (in script):


void main(float frameDelta)
{
   while ( something ) 
   {
      DoWork(frameDelta); // this frame delta appears to not change every time the script resumes

      SuspendMe();
   }
}

Is this a known behavior? Am I doing something wrong?

Thank you very much.

Advertisement

You can only set arguments on the context after Prepare() and before the first Execute(). The SetArg methods returns an error if not in this state. I bet you didn't check the return code, am I right? ;)

When a context is suspended and then resumed with another call to Execute() it will continue at the exact same position where it was suspended, which means that any function arguments that were passed into the function in the first call will already have been read and used. Even if the context would allow you to set the arguments while the context was suspended there would be no guarantee that the script would actually re-read the arguments when resuming.

If you mean to change the argument, why not allow the script to run to it end and then simply call the script again with the new argument? I.e. remove the while loop and the SuspendMe() call.

void main(float frameDelta)
{
  if( something )
    DoWork(frameDelta);
}

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

Thank you for the quick response! Indeed, I wasn't checking the return code from SetArg :) (I figured the param was on the stack and wasn't going to update until the function ended and I executed it again [not resumed]).

I ended up registering a global const float that I update every tick from C++ and I can check that in the scripts. That worked as expected.

My script function is significantly more complex and does have some state that I want to suspend/resume... i was just simplifying it for this example.

This topic is closed to new replies.

Advertisement