🎉 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!

variable persistence and does it make sense to have an 'idle loop'

Started by
0 comments, last by WitchLord 10 years, 6 months ago

Does it make sense to keep a script (context) running in an 'idle loop' - that is, if it doesn't need to do anything, then Suspend() itself (through a registered function).. and when it needs to do some work, to do that and go back to being idle (how would you even signal it that it needs to do some work.. through a global variable which is shared amongst all contexts of that script module?)? That way that function that you Execute()'d would maintain its local variables (because you keep it running).

Or is it idiomatic for AngelScript to maintain state through global variables?

How should you maintain state? Or is it expected that C++ maintains whatever game state and each time a script function runs, it queries whatever it needs to (through registered functions/objects) in order to gather the necessary variables to do its work?

Thank you.

Advertisement

Think of your first alternative as a parallel thread in your application. The application will allow the context to execute for a while, then the context will wait (suspend) until it is time to execute again.

The other option is more like to event handling. Anytime there is an event in the application, the context is executed to handle that even and may use global variables (or properties registered by the application) to keep state information between executions.

Both options are perfectly viable with AngelScript, and it will only depend on your preference.

In my opinion the second option is easier to implement and manage, for the same reason that a singlethreaded application is easier to implement and manage compared to a multithreaded application.

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