timed picture removal

I am trying to do a collision where there is a 5 second window before the object is destroyed while the collision is still taking place.
I have a see-saw that can receive downward force events from either the right or left. If either the right or left part of the see-saw
touch the floor for more than five seconds than the game is over.

So if the right side of the see-saw is weighted down and touching the floor on the right side you want to press a button that will make a downward force event on the left side that will push down the left side of the see-saw and the right side will rise up off the floor. And if done within the five second timer the game will not be over.

So I have this…

function onCollision(event)
if event.other.name == ‘floor1’ then
local timer1 = timer.performWithDelay(5000, gameOver1, 1)
–seeSaw:setFillColor(255, 0, 0)
end
end

the seeSaw is the object/name with the collision listener. So once the right (or left) side of the seeSaw hits the ground it will bounce up and the game will be over in five seconds. I want that not to happen since the collision is no longer taking place.

As for the gameOver1 function. I tried doing something with another function that would call a display.remove(timer1) before the
gameOver1 function is called, but no dice. Is it possible to remove the onCollision function after it is called but before the
5 seconds and gameOver1 function is called?

Once the onCollision function is called there is no stopping the gameOver1 function from running. This is true?

if so I maybe going about this incorrectly.

Also I can get the seeSeaw to turn red when it hits the ground, but how would I get it back to normal when no longer hitting the floor?

Thanks in advance for any help.

russell
[import]uid: 75779 topic_id: 18588 reply_id: 318588[/import]

You can stop it from hitting the floor and change it back to normal. (In future please post your code in < lua > and < /lua > tags so it’s more readable.)

Here’s how you’d do it;

[lua]function onCollision(event)
if event.other.name == ‘floor1’ then
if event.phase == “began” then
local timer1 = timer.performWithDelay(5000, gameOver1, 1)
–seeSaw:setFillColor(255, 0, 0)
elseif event.phase == “ended” then
timer.cancel(timer1)
–change seesaw color back to normal here
end
end
end[/lua]

This says that if the event starts (the seesaw is colliding with the ground) start the timer. If the seesaw moves off the ground then cancel the timer.

Make sense?

Peach :slight_smile: [import]uid: 52491 topic_id: 18588 reply_id: 71537[/import]

Yes it makes total sense thank you. It works great. I learn something new everyday! [import]uid: 75779 topic_id: 18588 reply_id: 71681[/import]

No worries - learning new things is a big part of the fun!

Peach :slight_smile: [import]uid: 52491 topic_id: 18588 reply_id: 71773[/import]