Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I noticed to my surprise that an event created with dispatchEvent(event) gets handled directly when called, and not together with other events at a specific phase of the frame loop. Two main reasons of having an event system are:

  • so that you can call code B from code A, but still want to prioritize code A.
  • to make sure there are no freaky loopedy loops where code A calls code B calls code A ... I wonder what Ansca's rationale behind having events being handled directly this way is. And does Corona handle loopedy loops and other such pitfalls gracefully?

The following code demonstrates dispatchEvent():

T= {}
Z = display.newRect(100,100,100,100)

function T.doSomething()
  print("T.doSomething: begun")
  local event = { name="myEventType", target=T }
  Z:dispatchEvent( event )
  print("T.doSomething: ended")

function Z.sayHello(event)
  print("Z.sayHello: begun and ended")
Z:addEventListener("myEventType", Z.sayHello)

print("Main: begun")
print("Main: ended")

However Ansca claims the contrary at

Can anyone clear this up a little?

( Using Corona simulator V 2012.840 )

share|improve this question

closed as too localized by Kylotan, doppelgreener, John McDonald, jcora, Josh Petrie Oct 1 '12 at 15:33

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Only their developers can tell you exactly why they chose to do something in a certain way. And since one member of staff is claiming that they do things one way, and you're asking why they actually do it another way, no answer could make sense - even if we could give a good reason for handling the event immediately, they are claiming they don't do so, therefore our reason would not apply to them! – Kylotan Sep 17 '12 at 18:54
Your absolutely right Kylotan. I have posted this question on Ansca a few days ago, but in my experience, answers come quicker on stack exchange than at Ansca and I realized that I couldn't wait that long. I also wanted to get some feedback from peers on whether I misinterpreted something or not. – Amoxus Sep 18 '12 at 17:32
That's fair enough. There are some good reasons to handle events immediately - eg. ease of debugging, clear relationship between cause and effect - but as you noted there are some good reasons not to do it that way, also. So what's most important is consistency and good documentation, whichever way is chosen! – Kylotan Sep 19 '12 at 1:11