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…

[code]
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

[import]uid: 59140 topic_id: 13969 reply_id: 313969[/import]

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)

[lua]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)[/lua]

inform us what problem was it afterall) [import]uid: 16142 topic_id: 13969 reply_id: 51401[/import]

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

[code]
local function reset_score()
score = 0
scoreField.text = score
end [import]uid: 59140 topic_id: 13969 reply_id: 51406[/import]