Question regarding for loops

Hi everyone, I just have a question regarding for loops so I hope you guys can help me out.

Heres my code:

local function circleBall()

local circles = display.newCircle( math.random(0, 320), -20, 15 )

circles:setFillColor ( 27, 157, 0 )

physics.addBody ( circles, {density=1.0, bounce=0.8} )

timer.performWithDelay ( 1000, circles )

end

for i = 1, 10 do

circleBall()

end

My goal is to let the circle fall from the sky(it is) but I want to let it fall one by one using timer.performWithDelay and for loops, like fall down 1 by 1 per second until all the circles are done falling, but now it all falls at the same time, I mean all 10 circles fall together, can anyone tell me how to make the circles fall one by one? Im a bit new to corona but I hope I will master it someday. 

thanks in advance to anyone who answers.

Hi and welcome to this forum!,

You’re not calling a function with your performWithDelay, but “circles”, which does not make much sense. You probably meant “circleBall”.

But easier than messing about with a for loop, you can simply use the third parameter of performWithDelay to set the number if iterations - something like this:

local physics = require "physics" physics.start() local function circleBall() local circle = display.newCircle( math.random(0, 320), -20, 15 ) circle:setFillColor ( 27, 157, 0 ) physics.addBody ( circle, {density=1.0, bounce=0.8} ) end timer.performWithDelay ( 1000, circleBall, 10 )

Hi and welcome to this forum!,

You’re not calling a function with your performWithDelay, but “circles”, which does not make much sense. You probably meant “circleBall”.

But easier than messing about with a for loop, you can simply use the third parameter of performWithDelay to set the number if iterations - something like this:

local physics = require "physics" physics.start() local function circleBall() local circle = display.newCircle( math.random(0, 320), -20, 15 ) circle:setFillColor ( 27, 157, 0 ) physics.addBody ( circle, {density=1.0, bounce=0.8} ) end timer.performWithDelay ( 1000, circleBall, 10 )