🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Suspend a function

Started by
2 comments, last by WitchLord 16 years, 2 months ago
I have a class, that is bind to AngelScript C++ code: class CWorld { public: int SelectUnit() { context->Suspend(); return 1; }; }; CWorld world; engine->RegisterGlobalProperty("CWorld world", &world); //run AngelScript code //context gets suspended //!!!here I try to change the return value context->Execute(); AngelScript code: void OnMove() { int c = world.SelectUnit(); //wait while user selects a unit and then resume the script, returning the id of the selected unit print(c); } When I run this code, world.SelectUnit() always returns 1, no matter what I do (tried all the methods of asIScriptContext class). Is it possible to somehow change the return value after suspending the context?
Advertisement
No, there is not. Unless you do the unit selection before the SelectUnit function returns.

The application function that calls the context->Suspend() will run to it's end and return to the context. Only after the context has stored the return value will the script execution be suspended.

I suggest you break up the action in two methods, like this:

// Tell script to wait until user has selected a unitworld.WaitForUnitSelection(); // Once script resumes it calls this function to obtain the selected unitint c = world.GetSelectedUnit(); 


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

Thanks, I already thought about this method and I guess that is the only option. For example, in Squirrel can yield the script, and before the resuming, push the result on the stack so that the function returns the new result. Isn't the result pushed on stack in AngelScript? If so, then maybe there is a method for modifying the stack.
I'll think about it. I may expand the debug routines to allow inspection/modification of stack values.

AngelScript always suspends the scripts between expressions, i.e. when there are no values on the stack. This makes it safer when multithreading and co-routines are used, as contexts won't accidentally modify objects/values referenced by other contexts. It also in preparation for a potential future feature where contexts can be serialized, i.e. storing the current stack on disk for later resuming.

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

This topic is closed to new replies.

Advertisement