• Advertisement
Sign in to follow this  

Update script function argument on resume from suspend

This topic is 1507 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Edited by iraxef

Share this post


Link to post
Share on other sites
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);
}

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement