Advertisement Jump to content
Sign in to follow this  

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

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

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!