I'm trying to make a game that is based on how many objects have spawned

For instance if you get to 10 balls spawned, then something happens, and if you get to 30 balls spawned then something else will happen.

I have a timer that goes to my ball spawning function five times and this function also has “bs = bs +1”
(at the very beginning I put bs = 0). So I’m thinking from what I learned that this should keep track of all the objects spawned through that one function. Now I made a separate function saying if(bs == 5) then physics.start () or whatever I need but for some reason it doesn’t work. I put up the main segment of my code that the problem should be in.
Greatly appreciating any help.

[lua]
local function gameOperator ()
if (bs == 5) then
local physics = require “physics”
physics.start()
physics.addBody( ball, “dynamic”, { density=3.0, friction=0.5, bounce=0.3 } )
end

end

local function ballSpawn ()
local ball = display.newImageRect (“ball_blue.png”, 100,100)
ball:setReferencePoint (display.CenterReferencePoint)
ball.x = math.random (50, _W - 50); ball.y = math.random (50, _H -400)

function ball:touch(e)
if(ready == true) then
if (e.phase == “ended”) then
clickedBall (self)

end

end

return true;

end

– increase bs every time balls are spawned

bs = bs + 1

ball: addEventListener (“touch”, ball)

ready = true

end[/lua] [import]uid: 35535 topic_id: 9260 reply_id: 309260[/import]

are you calling the gameOperator() function ever?
[import]uid: 34945 topic_id: 9260 reply_id: 33789[/import]

You need a Runtime to keep track of the gameOperator function.
I assume you declared the bs before you created the gameOperator function.

[lua]local bs = 0
– I prefer to create the object before I create the function

local gameOpertor = function()

if bs == 5 then
print(“do something”)
end
end

[import]uid: 12455 topic_id: 9260 reply_id: 33790[/import]