Problem with timing

Hi! Newbie here. I have a problem and any help is greatly appreciated. 

So I have an image and when you “click” it, some text will appear and after a fixed time, the text would disappear.

At first, the timing was OK but later on as the application continues to run, the duration of the appearance of the text seems to get shorter and shorter every time I click it.

Like it starts going to fast that you can barely read the text.

I’ve set the duration of how long the text will appear.

Does anyone know what the reason is?

Can you show the minimum of code that exhibits this problem?

This checks when it will destroy the “object” created.

local count = 0

function update_teacher( )

     if(allow_count == true) then

          if(count == 100) then

               destroy_response();

          end

          count = count + 1;

      end

end

function update_game( )

     update_teacher();

     update_combination();

end

Runtime:addEventListener(“enterFrame”, update_game);

This is the one that will be executed.

local function destroy_response ( )

     --update teacher image back to normal

     count = 0;

     display.remove(teacher);

     teacher = design.change_sequence(1);

     group:insert(teacher);

     teacher:addEventListener(“tap”, teacher_on_tap);

    --teacher text response

    allow_count = false;

    display.remove(teacher_response);

    design.destroy_teacher_response();

end

It feels like you’re adding the enterframe listener more than once. Do you do this somewhere else other than the above, or is the above all inside a function that is called multiple times?

Solved it :slight_smile: Thanks hasty. Turns out I was adding the enterframe listener more than once. 

Can you show the minimum of code that exhibits this problem?

This checks when it will destroy the “object” created.

local count = 0

function update_teacher( )

     if(allow_count == true) then

          if(count == 100) then

               destroy_response();

          end

          count = count + 1;

      end

end

function update_game( )

     update_teacher();

     update_combination();

end

Runtime:addEventListener(“enterFrame”, update_game);

This is the one that will be executed.

local function destroy_response ( )

     --update teacher image back to normal

     count = 0;

     display.remove(teacher);

     teacher = design.change_sequence(1);

     group:insert(teacher);

     teacher:addEventListener(“tap”, teacher_on_tap);

    --teacher text response

    allow_count = false;

    display.remove(teacher_response);

    design.destroy_teacher_response();

end

It feels like you’re adding the enterframe listener more than once. Do you do this somewhere else other than the above, or is the above all inside a function that is called multiple times?

Solved it :slight_smile: Thanks hasty. Turns out I was adding the enterframe listener more than once.