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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 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
  

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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()

yes it is what i need to learn, to can make on my game, thank you very much darkconsoles :)

views:1376 update:2011/10/17 8:58:49
corona forums © 2003-2011