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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

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

j

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

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

1
2
3
4
5
function newBall(platform, velocity)
  local ball
 
  if platform == "iPad" then
    ball = ...etc...

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

Thanks a lot!

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

views:1389 update:2011/10/6 9:28:12
corona forums © 2003-2011