Once upon a Runtime

thank you for a million answers for my previous issue!
Finally, I resolved it.

But, now I have another newbinteresting question: is it possible to start this only once -
Runtime:addEventListener ("enterFrame", someFunction)
without the subsequent or specified before
Runtime:removeEventListener ("enterFrame", someFunction)

Help me, please, to figure it out, I can’t sleep a week :confused:


So, Runtime:addEventListener ("enterFrame", someFunction) will result in someFunction being called once every frame until you explicitly remove the event listener using Runtime:removeEventListener ("enterFrame", someFunction). Until you’ve removed the existing enterFrame listener, you shouldn’t go adding more.

So, if you need to stop someFunction from being called every frame, then you must remove it.

@XeduR, fantastic! I have a function to check (or chech?) an object’s color change at a key moment of the gameplay. With “enterFrame” it works perfectly. But, on the other hand, I receive an infinite amount of messages in Corona console…

If you need to check for some value at a particular time during gameplay, then you shouldn’t be using enterFrame for that. Just check it once when you need to. Keep enterFrame for things that need updating constantly.

1 Like

@XeduR, well, Gordon Freeman, I understood nothing, but me and my brother will send a couple of words to Santa about your invaluable precepts! :slight_smile:

I have a function to check (or chech?) an object’s color change at a key moment of the gameplay.

If you need to check an object’s colour change at a key moment of gameplay, like you said, then you should only check it at that moment.

enterFrame runs every frame, i.e. either around 30 or 60 times per second (depending on what you’ve set in your config.lua). This means that using an enterFrame listener would be terribly inefficient if you don’t need to check that information all the time.

For instance, if you need to know the colour change when two objects collide, or when the user presses some button, etc. then you need to run the function only whenever that “key moment of gameplay” of yours occurs.

1 Like