Sign in to follow this  

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

Recommended Posts

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.

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this