Question how timers interact with touch events...

I have a timer.performWithDelay that is running the main game thread of my app inorder to update ai elements. Lets call this timerFunction.

I also have a touch listener running to handle player input that responds to event.phase == “ended”. Lets call this touchFunction

Is it possible that in the middle of the timerFunction  being executed  the touchFunction runs, effectively splitting the execution of the timerFunction? 

Is it possible that in the middle of the touchFunction  being executed  the timerFunction runs, effectively splitting the execution of the touchFunction?

In my game I am having a bug that occurs rarely and it has eluded me for months. Could this be the cause?

Thanks!

Hi!

I’m pretty sure the touch is not “splitting” your timerFunction. Code blocks tend to be executed completely in Lua.

There’s an easy way to check this, however. Print “timerFunction Started” at the start of the function and “timerFunction Ended” at the end of the function. Print “TouchFunction Started” at the start of the touch function.  If your code is split, the touch printout will be in between the timerfunction start and end.

Even if it splits your code, there are easy ways to catch and fix this. You could, for example, set a variable to true or false with the touch, and only check for this variable at the start of your timerFunction.

Hi!

I’m pretty sure the touch is not “splitting” your timerFunction. Code blocks tend to be executed completely in Lua.

There’s an easy way to check this, however. Print “timerFunction Started” at the start of the function and “timerFunction Ended” at the end of the function. Print “TouchFunction Started” at the start of the touch function.  If your code is split, the touch printout will be in between the timerfunction start and end.

Even if it splits your code, there are easy ways to catch and fix this. You could, for example, set a variable to true or false with the touch, and only check for this variable at the start of your timerFunction.