Generate and remove Object at the same time?

Function doCountdown()

   

local currentTime = countDownText.text

currentTime = currentTime -1

countDownText.text = currentTime

     if(currentTime == 0)  then

     display.remove(allBallsGroup)

     countDownText.text = gameTime

     startTimer()

     generateBalls()

    end

end

The situation here is the Timer has 15 sec, so if it hit to 0 all the group of objects will be removed display.remove(allBallsGroup) and will replace by the new group objects which means generateBalls()? How can i do this in the same time?

Please only ask your question once. I’ve removed your other post.

Rob

It’s impossible to say going by the code you’ve posted. Are you getting an error message? What do you expect to happen, and what is actually happening?

The error message is this: 

Addition.lua:238 attempt to call method ‘insert’(a nil value)

stacktraceback:

                       Addition.lua:238 in function ‘_listener’

                       ?: in function <?:167>

                       ?: in function <?:221>

Heres my code: 

(238.) allBallsGroup:insert(ballGroup)

(167.) display.remove(allBallsGroup)

(221.) ball.height = 200;

Simply, What i really wanted to happen is just like a crate falling down with a timer and if the timer hits to 0 the crate will be gone then will generate a new falling crate again with the timer then if  hit 0 again then it will be replace by a new create and so on and on.

Its like a loop that always restart , im sorry i didnt reply to this topic because im working on it and still can’t figure it out …

Well, the error message is saying that, on line 238, allBallsGroup is nil. I’ll assume you are putting allBallsGroup = display.newGroup() somewhere above. If you are getting this error straight away, make sure you don’t have a typo in “allBallsGroup”. If you get this error later on, I would guess it is sometime after you call display.remove(allBallsGroup), which will set allBallsGroup to nil. You’ll need to call allBallsGroup = display.newGroup() again at some point to recreate the display group. Alternatively, instead of removing this group, you could just remove its children.

for i = 1, allBallsGroup.numChildren do display.remove(allBallsGroup[1]) end

It works but it only generates twice and not consistently, error still occurs but a different one

I remove the gameover function and the drop of balls is now consistent Thanks mate :))

Now i need to work on arithmetic (In which the crate has a number and and there would be a generated arithmetic expression like

2+2 = ? then ill find the missing number by choosing the correct crate with num)

Please only ask your question once. I’ve removed your other post.

Rob

It’s impossible to say going by the code you’ve posted. Are you getting an error message? What do you expect to happen, and what is actually happening?

The error message is this: 

Addition.lua:238 attempt to call method ‘insert’(a nil value)

stacktraceback:

                       Addition.lua:238 in function ‘_listener’

                       ?: in function <?:167>

                       ?: in function <?:221>

Heres my code: 

(238.) allBallsGroup:insert(ballGroup)

(167.) display.remove(allBallsGroup)

(221.) ball.height = 200;

Simply, What i really wanted to happen is just like a crate falling down with a timer and if the timer hits to 0 the crate will be gone then will generate a new falling crate again with the timer then if  hit 0 again then it will be replace by a new create and so on and on.

Its like a loop that always restart , im sorry i didnt reply to this topic because im working on it and still can’t figure it out …

Well, the error message is saying that, on line 238, allBallsGroup is nil. I’ll assume you are putting allBallsGroup = display.newGroup() somewhere above. If you are getting this error straight away, make sure you don’t have a typo in “allBallsGroup”. If you get this error later on, I would guess it is sometime after you call display.remove(allBallsGroup), which will set allBallsGroup to nil. You’ll need to call allBallsGroup = display.newGroup() again at some point to recreate the display group. Alternatively, instead of removing this group, you could just remove its children.

for i = 1, allBallsGroup.numChildren do display.remove(allBallsGroup[1]) end

It works but it only generates twice and not consistently, error still occurs but a different one

I remove the gameover function and the drop of balls is now consistent Thanks mate :))

Now i need to work on arithmetic (In which the crate has a number and and there would be a generated arithmetic expression like

2+2 = ? then ill find the missing number by choosing the correct crate with num)