Why wont this timer work?

I got this code:

local function spawnBubble( event )
diplay.newImage(“Images/Bubble.png”, math.random(15, 300), 460)
end
timer.performWithDelay(
1, spawnBubble )

I want it to every 1 second spawn a bubble at a random position between 15-300 on the x-axis and 460 on the y-axis

Why doesn’t this work [import]uid: 14018 topic_id: 5092 reply_id: 305092[/import]

I’m assuming that the problem is you get only one bubble - I haven’t tested your code, and you didn’t say how it doesn’t work.

First thing I notice is that it’s not set to spawn after 1 second, but 1 millisecond. Secondly, you haven’t specified the number of iterations (0 for infinite) so it will only spawn once.

I’m also assuming that diplay.newImage is a forum typo as it should be display.newImage.

To spawn an infinite number of bubbles once per second:

[lua]timer.performWithDelay( 1000, spawnBubble, 0)[/lua]

To spawn 25 bubbles once per second:

[lua]timer.performWithDelay( 1000, spawnBubble, 25)[/lua]

You can read about timer functions and how to cancel them here:
http://developer.anscamobile.com/content/timer-library [import]uid: 11393 topic_id: 5092 reply_id: 16780[/import]

Thanks, I did not notice that typo since I copied the code from a tutorial. I assumed they tested their code lol [import]uid: 14018 topic_id: 5092 reply_id: 16788[/import]

Nahir, you should really consider typing out your own code; then when you look at the terminal and see what line an error is on you can fix it yourself because you’ll understand, over time, what a timer should look like :slight_smile:

Just my two cents - I write a lot of tutorials and I know there have been times I’ve made errors others have pointed out to me. :slight_smile: It happens! [import]uid: 10144 topic_id: 5092 reply_id: 16819[/import]