Does enterFrame event listener skip frames?

I didn’t see a topic about this and there doesn’t seem to be a gotcha about this, but in my code I do

local frameCount = 0 obj:state1() -- obj should reset to this after 60 frames obj:state2() obj:enterFrame() frameCount = frameCount + 1 if frameCount == 60 then frameCount = 0 obj:state1() end end Runtime:addeventlistener("enterFrame", obj)

Sometimes the obj gets stuck in state 2 and never resets to state1. I’m not sure of any other reason this might happen, other than the frameCount not triggering or skipping 60. Is that because the enterFrame event listener is skipping the code or frame somehow?

I refuse to believe that something is happening to cause the enterFrame event listener to actually skip code. I also think the code you’ve presented here is not everything you’ve got in your listing.

Having said that, could you try a modification along these lines to see if the ‘60’ value actually gets skipped, as you surmise…

local frameCount = 0 local frameCountMoreThanSixty = false obj:state1() -- obj should reset to this after 60 frames obj:state2() obj:enterFrame() frameCount = frameCount + 1 if frameCount \> 60 then frameCountMoreThanSixty = true print("skipped!") end if frameCount == 60 then frameCount = 0 obj:state1() end end Runtime:addeventlistener("enterFrame", obj)

Yeah I did try >= 60 without any problems so far, and I would have tested it but I don’t know how to recreate the bug and it happens rarely so it’s hard to get feasible results. But I will still try to test it, for the meantime does anyone else have any ideas

Guess what, I just did a quick test and I guess I was right. The frameCount is skipping past 60 without triggering the reset to 0.

Here’s a screenshot of the console,

https://postimg.org/image/b8oc6jvmd/

The 200+ number is the frameCount. It only seems to happen when there are many enemies on the screen so it might be caused by lag, but even so why would the code skip a frame?

UPDATE: Nevermind! It had nothing to do with the enterFrame listener, which is a relief :D. It was a simple mistake on my part, thanks for the help.

I refuse to believe that something is happening to cause the enterFrame event listener to actually skip code. I also think the code you’ve presented here is not everything you’ve got in your listing.

Having said that, could you try a modification along these lines to see if the ‘60’ value actually gets skipped, as you surmise…

local frameCount = 0 local frameCountMoreThanSixty = false obj:state1() -- obj should reset to this after 60 frames obj:state2() obj:enterFrame() frameCount = frameCount + 1 if frameCount \> 60 then frameCountMoreThanSixty = true print("skipped!") end if frameCount == 60 then frameCount = 0 obj:state1() end end Runtime:addeventlistener("enterFrame", obj)

Yeah I did try >= 60 without any problems so far, and I would have tested it but I don’t know how to recreate the bug and it happens rarely so it’s hard to get feasible results. But I will still try to test it, for the meantime does anyone else have any ideas

Guess what, I just did a quick test and I guess I was right. The frameCount is skipping past 60 without triggering the reset to 0.

Here’s a screenshot of the console,

https://postimg.org/image/b8oc6jvmd/

The 200+ number is the frameCount. It only seems to happen when there are many enemies on the screen so it might be caused by lag, but even so why would the code skip a frame?

UPDATE: Nevermind! It had nothing to do with the enterFrame listener, which is a relief :D. It was a simple mistake on my part, thanks for the help.