Help with timer.performWithDelay

Hello, I’m making a game where objects spawn from top and keep falling until he character’s health is greater than 0

here is what I am doing:  

timer.performWithDelay (math.random(400,800), spawnObject,0)

so basically the 0 states that it will loop for ever. How can I put in a condition their to check if health if >0 then counitnue to spawn or stop?

Can you post the code that counts the players health? 

The timer should be working fine…

Maybe add a variable to it incase you want to cancel it later?

At the top of your scene:show im guessing is where your game starts? Add this :: 

local timer1

then the timer ::

timer1 = timer.performWithDelay(math.random( 400, 800 ), spawnObject, 0)

Good Luck!

this is because when you first call the timer.performwithDelay, it will only get the random number once. You should put in a function like this, so you will get a random number all the time

local function randomSpawning() local tmpTimer = timer.performWithDelay (math.random(400,800), spawnObject) -- You need to timer.cancel it later, else it will crash when you change scene! end timer.performWithDelay ( 10, randomSpawning, 0)

Hey, to count the health, I am using health =5 right at the top of the scene so its a globar variable and down somewhere, where I have the collision code on every collision began health = health -1 this is what I am doing, the health is working fine. How ever if I use timer.cancel(timer1) here it does not cancel it. But if I say print(timer1) it does print up and how me some address so that means timer1 is accesible their but timer.cancel is not working from their. Moreover if ryt at the end I spawn my objects their and then use the timer.cancel it works fine and does not show any objects as it cancels it before it runs. please help

Hey, Like i asked before can you post some code? Its hard to understand the problem and see the problem when theres no problem to see. Thanks!

Can you post the code that counts the players health? 

The timer should be working fine…

Maybe add a variable to it incase you want to cancel it later?

At the top of your scene:show im guessing is where your game starts? Add this :: 

local timer1

then the timer ::

timer1 = timer.performWithDelay(math.random( 400, 800 ), spawnObject, 0)

Good Luck!

this is because when you first call the timer.performwithDelay, it will only get the random number once. You should put in a function like this, so you will get a random number all the time

local function randomSpawning() local tmpTimer = timer.performWithDelay (math.random(400,800), spawnObject) -- You need to timer.cancel it later, else it will crash when you change scene! end timer.performWithDelay ( 10, randomSpawning, 0)

Hey, to count the health, I am using health =5 right at the top of the scene so its a globar variable and down somewhere, where I have the collision code on every collision began health = health -1 this is what I am doing, the health is working fine. How ever if I use timer.cancel(timer1) here it does not cancel it. But if I say print(timer1) it does print up and how me some address so that means timer1 is accesible their but timer.cancel is not working from their. Moreover if ryt at the end I spawn my objects their and then use the timer.cancel it works fine and does not show any objects as it cancels it before it runs. please help

Hey, Like i asked before can you post some code? Its hard to understand the problem and see the problem when theres no problem to see. Thanks!