Why is my multi-touch listener working?

I have been struggling with multi-touch and finally got it working, but on accident. I added a print statement in my event handler just for troubleshooting purposes and it caused my multi-touch listener to start doing what I wanted it to do. I asked on stackoverflow why this happened, but I didnt get a response so I’m re-posting it here. Here’s my original post:

function multitouchHandler(event) if ( "began" == event.phase ) then myTable[event.target.id] = true end if ( "ended" == event.phase ) then if thisObject == currentObject then removeObject() else print("This object isn't the current object.") endProgram() end end end

This is a multi-touch event handler that is called by two objects being touched at the same time. The code works and does what I want it to do, but I’m not sure why.

It actually started working when I got frustrating not knowing what was wrong so I added print() statements throughout my entire project to help me troubleshoot. To my surprise when I added the print() statements, multi-touch started working.

One by one I removed them until I figured out which one was actually causing my multi-touch listener to start working and it turns out to be the one in the above code. If I take out the print() statement, multi-touch stops working.

This isn’t the exact code in my program, but it’s summarized to act like the listener. I would like to know why the print() statement is needed. It seems to add a long enough ‘pause’ to make the multi-touch return the “if thisObject == currentObject” condition to true, but if that’s the case then I would think there is a better way to create this pause.

(currentObject is chosen by two objects being touched and then compared to the currentObject)

Comment out that print statement and put one in endProgram() - to see if it fires. If it does then i think the problem lies with for thisObject == currentObject line

Without exact code that’s about all the forum can do for you - suggest an area to look at!

So focus your attention on your logic relating to that line.

When you find the error remember to post something about what you did wrong.

T.

Comment out that print statement and put one in endProgram() - to see if it fires. If it does then i think the problem lies with for thisObject == currentObject line

Without exact code that’s about all the forum can do for you - suggest an area to look at!

So focus your attention on your logic relating to that line.

When you find the error remember to post something about what you did wrong.

T.