Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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")
end

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

print("Main: begun")
T.doSomething()
print("Main: ended")

However Ansca claims the contrary at http://developer.coronalabs.com/reference/index/objectdispatchevent

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, jco, 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.

1  
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

Browse other questions tagged or ask your own question.