Jump to content

Basic Question About States, Events, and Event Handlers


GManB
 Share

You are about to reply to a thread that has been inactive for 1418 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I have not programmed in a completely event driven model as scripting here seems to be. Thus, a newbie question, I am sure.

Where do I put a long running loop? It seems from some testing that if I put a loop based on a global conditional in state_entry (in either the default or my own state) as long as the loop is running the event that generated entry into state_entry does not complete. And, no other event in that state, such as touch_start, will be triggered.

Is this correct?

The model I seem to be building in my head is that there is a single, global event queue per script. When an event comes off the queue it goes to the current state the script is in. There it causes execution of its associated event handler. While that event handler is executing no other event will come off the queue. When, and only when, that event handler completes will the next, if there is one, event come off the queue.

Is that model about right?

 

Thanks,

G

Link to comment
Share on other sites

Yes, and yes.

If you want to allow constantly repeating code to be interrupted you can put it in a timer event. The timer will persist over changed states, but you'll need the appropriate code in the timer event for each state. The code in the timer event must first finish before another event is triggered.

Edited by KT Kingsley
  • Like 1
Link to comment
Share on other sites

if you want to catch other events while your "long running loop"... is running, you'll have to make sure it interrupt itself and re-schedule a time to resume.

Scripts only have one execution pointer, you cannot be in two events at the same time.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1418 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...