Reset Score [RESLOVED]

I have a scoreText.score code and it works great but I don't know how to reset it back to 0 after the user hits "retry".

I have the variable set up and the point system working. The thing that makes it tough is I don't know many points the user will get so I can't just subtract it. I tried just coding "score = 0" but I caught another apple(a point) and it added to the previous score.

The code...

1
2
3
4
5
6
7
8
9
10
11
12
local score = 0
 
--the text
local apple = display.newImage ( "Red Apple.png" )
physics.addBody(apple, {density=3.0})
apple.x = -30
apple.y = 370
apple.name = "apple"
 
--and this is what I have in between if-then statements
scoreText.text = score
                                score = score + 1

i dont know what exactly causing your problem, but i tried something like that and it works just fine

its not a pretty code, but i hope you will understand)

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
local physics = require("physics")
physics.start()
 
local score = 0
 
local scoreField = display.newText("", 50,50, native.systemFont, 100)
 
local function add_score()
        score = score + 1
        scoreField.text = score
end
 
local function boxes()
thing = display.newRect(50,10, 50,50)
physics.addBody(thing)
thing.name = "thing"
end
 
boxes()
 
local bound = display.newRect(10,700, 400,10)
physics.addBody(bound, "static")
bound.name = "bound"
 
local function onCollision(event)
        if event.other.name == "thing" then
                add_score()
        end
end
 
bound:addEventListener("collision", onCollision)
 
local function reset_score()
        score = 0
        scoreField.text = score
        end
 
 
local reset = display.newText("RESET", 150, 50, native.systemFont, 50)
reset:addEventListener("touch", reset_score)

Hey thanks! I just tweaked the code below and it worked great!

1
2
3
4
local function reset_score()
        score = 0
        scoreField.text = score
        end
views:1086 update:2011/10/11 15:24:38
corona forums © 2003-2011