Need a Suggestion

I’m having trouble accomplishing this, every time this object hits the ground I want some text to increase by one. The problem is that it always bounces when it hits the ground which is fine but, every time it bounces the counter goes up by each time it bounces when I want it to only go up by once. Any suggestions to accomplish this? [import]uid: 12041 topic_id: 5001 reply_id: 305001[/import]

You could try to attach a boolean to the object when created, it will pass a check only the first time you set it.

Not sure if this fits in with what you’re trying to do…

[lua]object.counted = false – Set this when creating the object

function bounceHandler( event ) – Event which is triggered on bounce
if not event.target.counted then – Will only pass this check the first time
counter = counter + 1 – Increment counter
event.target.counted = true – Set boolean so it doesn’t get counted again
end
end[/lua] [import]uid: 11393 topic_id: 5001 reply_id: 16321[/import]

Thanks for that wouldn’t work exactly like that since I would need to add a timer to a function that would reset the boolean to false after like 10 seconds. [import]uid: 12041 topic_id: 5001 reply_id: 16326[/import]

You could add a delayed function in the eventHandler to reset the object after 10 seconds:

[lua]event.target.counted = true – Set boolean so it doesn’t get counted again

timer.performWithDelay(10000, function() if event.target then event.target.counted = false end end , 1) – After 10 seconds check if object still exists and reset counter[/lua] [import]uid: 11393 topic_id: 5001 reply_id: 16350[/import]