Add score in runtime function

Hi,

can someone tell me how to properly add scores inside of an enterFrame function?

like:

1
2
3
4
5
6
7
local function foo()
if var == 1 then
scorevar = scorevar + 100
end
end
 
Runtime:addEventListener("enterFrame", foo)

timer.performWithDelay(1, foo, 1)

A timer that only performs once after 1/1000 of a second. :D

For many games, you get points when you do something. But @IKink's idea is good for the games where you get points for time based things, like points for surviving.....

The other way is to keep track of the number of frames, lets say your a 30 fps app, try something like this in your :

1
2
3
4
5
6
7
8
9
   local frameCount = 0
   local function foo()
       frameCount = frameCount + 1
       if frameCount > 30 then
           scorevar = scorevar + 100
           frameCount = 0
       end
   end
   Runtime:addEventListener("enterFrame", foo)

i need something different i think
i have this:

1
2
3
4
5
6
7
8
9
10
11
12
if t[many].part1.health >= 100 and t[many].part2.health >= 100 and t[many].part3.health >= 100 then
                                        
                                        t[many].part1Complete = true
                                        t[many].part2Complete = true
                                        t[many].part3Complete = true
                                        astroScore = astroScore + 300
                                        shipScore = shipScore + 300
                                        scoreTextField.score = scoreTextField.score + 300
                                        scoreTextField.text = string.format("SCORE: %05d", scoreTextField.score)
                                
                        
                                end

Last time I use something like this to check every secound is level up:

1
2
3
4
5
6
7
8
9
10
                                        local increaseLevel = function()
                                                local round = math.ceil
                                                if ( round ( Points / 1000 ) > level ) then
                                                        
                                                        level = level + 1
                                                        ...
 
                                                end
                                        end
                                        timer1 = timer.performWithDelay(1000, increaseLevel, 0)
views:1349 update:2011/12/1 20:56:45
corona forums © 2003-2011