0

I am using a similar syntax and method to the one used to spawn multiple bricks. I first use a function in my Powerup class to put three ball classes in one table:

function Powerup.triple(x, y, skin)
  local balls = {}
  c = Ball(x, y, skin)

  for i = 1, 3 do
    table.insert(balls, c)
  end
  return balls
end

Then I transfer this to the play state while in the serve state using

gStateMachine:change('play', {
...
balls = Powerup.triple(self.ball.x, self.ball.y, self.ball.skin),
...
})

Then in the play state, I use for loops to treat them separately. Ex:

for k, ball in pairs(self.balls) do
    ball.dx = math.random(-200, 200)
    ball.dy = math.random(-50, -60)
end

Like I said, I use pretty much the same syntax as the bricks. My problem is, unless all of them have their inPlay variable be true, they won't spawn upon going to the play state, and if all of them are in Play, then it just spawns one ball that goes much faster than it's supposed to. My best guess for why this happens is that it applies all the variable changes to one singular ball class, but I'm completely lost as to what I am doing wrong.

1 Answer 1

0

I figured it out. In Powerup.triple the c is supposed to be inside the for loop, like this:

function Powerup.triple(x, y, skin)
local balls = {}

for i = 1, 3 do
    c = Ball(x, y, skin)
    table.insert(balls, c)
end
return balls
end

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .