# Update script function argument on resume from suspend

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

## 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 on other sites

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 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.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 9
• 15
• 9
• 11