Variable value update

hello corona community, i need help urgently, i need to update the value of one variable but i have some doubts about that.

 function new  
--require physics etc  
  
--big pausegame function  
  
--big startgame function  
  
--and it is the importante part, my active default value is 0 but when i touch on the ball i need to change the variavel active value to 1 because of the if loop  
 local that = function ()  
 local active = 0  
 physics.start( true )  
 physics.setDrawMode( "normal" )   
 physics.setGravity( 0,0 )  
  
 local ball1 = display.newCircle( 80, 120, 20 )   
 ball1:setFillColor( 0, 255, 0 )   
 physics.addBody(ball1,"kinematic", { density=2, bounce=0.3, radius=25});  
 ball1.x = 250; ball1.y = 200  
 game\_objects:insert( ball1 )  
  
 local ball\_func = function()  
  
 function ball1:touch( event )  
  
 if(event.phase == "ended") then  
 active = active + 1  
 ball1.bodyType="dynamic"   
 physics.setGravity (0,9.8)  
 end  
 end  
 ball1:addEventListener( "touch", ball1 )  
 end  
  
 ball\_func()  
  
  
  
 if active == 0 then  
 pausegame()  
 elseif active == 1 then  
 startgame()   
 end  
 end  
  
 that()  
 return game\_objects  
end  

i really want to know how i can make it, because will very importante to my game and future games.

Thanks people [import]uid: 26056 topic_id: 15823 reply_id: 315823[/import]

you trying do check variable upon object creation or function call, but its not gonna work this way

maybe this solution can help, i didnt think about it much thou
[lua]active = 0
local function foo()
local group = display.newGroup()

local ball = display.newCircle(0,0,50)
group:insert(ball)
local function touch(event)
if event.phase == “ended” then
active = active + 1
print(active)
end
if active > 10 then
print(“over 10”)
end
end

function act()
if active == 2 then
print(“two”)
end
end

ball:addEventListener(“touch”, touch)

Runtime:addEventListener(“touch”, act)

return group
end

local obj = foo()[/lua] [import]uid: 16142 topic_id: 15823 reply_id: 58466[/import]

yes it is what i need to learn, to can make on my game, thank you very much darkconsoles :slight_smile: [import]uid: 26056 topic_id: 15823 reply_id: 58472[/import]