Add score in runtime function

Hi,

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

like:
[lua]local function foo()
if var == 1 then
scorevar = scorevar + 100
end
end

Runtime:addEventListener(“enterFrame”, foo)[/lua]

But it adds scores way too much times and i only need once
is there a proper way to do this kind of thing?

any help is appreciated of course) [import]uid: 16142 topic_id: 18356 reply_id: 318356[/import]

timer.performWithDelay(1, foo, 1)

A timer that only performs once after 1/1000 of a second. :smiley: [import]uid: 103624 topic_id: 18356 reply_id: 70376[/import]

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 :

 local frameCount = 0  
 local function foo()  
 frameCount = frameCount + 1  
 if frameCount \> 30 then  
 scorevar = scorevar + 100  
 frameCount = 0  
 end  
 end  
 Runtime:addEventListener("enterFrame", foo)  

There are other variants of this where you would get system time and test to see if its greater than your time frame that will work too.
[import]uid: 19626 topic_id: 18356 reply_id: 70382[/import]

i need something different i think
i have this:
[lua]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[/lua]

and i need to add score just once, not repeat it infinite times, but without removing event listener, because i need it to be there
[import]uid: 16142 topic_id: 18356 reply_id: 70389[/import]

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

[lua] local increaseLevel = function()
local round = math.ceil
if ( round ( Points / 1000 ) > level ) then

level = level + 1

end
end
timer1 = timer.performWithDelay(1000, increaseLevel, 0)[/lua]
[import]uid: 12704 topic_id: 18356 reply_id: 70406[/import]