Cannot insert table into group

I have been using the balloon burst video tutorials to build a game by Dr Rafael Hernandez. I am having some major issues with the insert function. Here is the code:

  
local function spawnBalls()  
 local function spawn(e)  
  
 local b = ball.newBall("iPhone", m.rand(50, 75))  
  
 --Store the instance in the balls table  
 balls[b] = b  
  
 --Flag the balls for removal later  
 balls[b].remove = true  
  
  
 foreground:insert(balls[b])  
  
 end  
  
 spawn()  
  
 local tmr = timer.performWithDelay(frequency, spawn, 4)  
  
 end  
  

If I try to insert the balls table (haha, lets be mature!) then I get a runtime error every time:
Runtime error
/Users/Kyle/Desktop/Project “Color Burst”/game.lua:137: bad argument #-2 to ‘insert’ (Proxy expected, got nil)
If I use any other object (text, rect, and images for example) it gives no error. Anyone else having this problem or know why it wont allow it? I have double checked as much code as I can and it is identical to the code in the video, but I CANNOT get it to work correctly. Thanks!

[import]uid: 9968 topic_id: 8573 reply_id: 308573[/import]

looking at the above code, it looks like [lua].remove[/lua] is possibly a reserved keyword and you’ve overridden it (thus possibly breaking it). just a guess though. try using [lua].removable[/lua] or something as your flag and see if that changes anything. otherwise are you sure [lua]ball.newBall[/lua] actually returns a display object? can we see your code for that?

j [import]uid: 6645 topic_id: 8573 reply_id: 30796[/import]

I removed the .remove completely just to test it out and still getting the same error. I am using display.newCircle to create the balls. Here is my code:

function newBall(platform, velocity)  
  
  
 if platform == "iPad" then  
  
 local size = m.rand(30, 80)  
  
 local ball = display.newCircle(0, 0, size)  
 ball:setFillColor(200, 255, 100)  
 ball.x = m.rand(90, 680); ball.y = -100  
  
 elseif platform == "iPhone" then  
  
 local size = m.rand(15, 40)  
  
 local ball = display.newCircle(0, 0, size)  
 ball:setFillColor(200, 255, 100)  
 ball.x = m.rand(50, 270); ball.y = -50  
  
 return ball  
end  

I could go ahead and try making it using display.newImage and see if that makes a difference. [import]uid: 9968 topic_id: 8573 reply_id: 30963[/import]

you’ve got ball defined locally inside your if statement. believe it or not that means it is local to the if statement

do this

[lua]function newBall(platform, velocity)
local ball

if platform == “iPad” then
ball = …etc…[/lua] [import]uid: 6645 topic_id: 8573 reply_id: 30970[/import]

Works perfectly! I wan unaware that if defined in the if statement the object will be local to that if statement.

Thanks a lot! [import]uid: 9968 topic_id: 8573 reply_id: 30978[/import]

i didn’t realise either. what i was surprised by was it was letting you define the variable locally twice in one function, which is what led me to think it was creating them local to each condition

glad it’s working for you now anyway [import]uid: 6645 topic_id: 8573 reply_id: 31007[/import]