Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

Update script function argument on resume from suspend


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 iraxef   Members   -  Reputation: 348

Like
0Likes
Like

Posted 02 December 2013 - 11:22 AM

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, 02 December 2013 - 01:14 PM.


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3352

Like
1Likes
Like

Posted 02 December 2013 - 07:15 PM

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

#3 iraxef   Members   -  Reputation: 348

Like
0Likes
Like

Posted 02 December 2013 - 08:17 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS