Score is increasing at different rate. Help!!!!

Ok. I have a game that is all about how long you can survive. The score goes up by three for every second you can last. However, if you go to menu and then start a new game again it increases by six. If you go to menu and back it goes to nine. Why is this?

Here is the score code:
score = 0;
function addScore(e)
score=(score +3);
scoreNumbText.text = score;
end
time2 = timer.performWithDelay(1000, addScore, 0) [import]uid: 49677 topic_id: 8754 reply_id: 308754[/import]

did you cancel your time2 and nil it out when you exit to menu?

When you said menu, i assume you mean the main menu screen.

if you’re using director class, then you can do this

[lua]-- if you’re using director class 1.2 modified by jonathan beebe
– create a cleanup function

cleanUp = function()
if time2 then
timer.cancel(time2)
time2 = nil
end
end

– hopefully, this is what you’re looking for. [import]uid: 12455 topic_id: 8754 reply_id: 31900[/import]

Thanks for the reply. I am using the director class, but where would i insert that code to utilize it? My game is set up like this:

if PlayReady then

–game functions–
if the Menu picture is touched, then playready = false and you are taken back to the main menu

–timers–

end

thats basically how it is. [import]uid: 49677 topic_id: 8754 reply_id: 31934[/import]

You would insert that code at the very bottom before you close your function.

[lua] local localGroup = display.newGroup()
function new()

– game code goes here

– the cleanUp goes here

cleanUp = function ()

if time1 then
timer.cancel(time1)
time1 = nil
end
end

return localGroup

end

– hope this help…
[import]uid: 12455 topic_id: 8754 reply_id: 31936[/import]

Hmm for some reason everything i try doesnt work. Is there anyway that by going to the Menu scene that i can delete the Game scene and make it create a new one upon choosing to play the game?

The game works fine… its just the problems when going out to the menu and trying to play again [import]uid: 49677 topic_id: 8754 reply_id: 31938[/import]

yes… that’s where the magic of director class will do for you, but you’ll have to put everything into the local Group.

is the error still the same or is it different now?
[lua] local localGroup = display.newGroup()
function new()
– example
image1 = display.newImageRect(“image.png”, 50,500
image1.x = 50
image1.y = 50

localGroup:insert(image1)

– in my game I used clean instead of cleanUp
clean = function ()
– code goes here
end

return localGroup
end

– and that should be it… unless you messed up somewhere in your
– code, then it might create a problem, but without seeing the
– rest of your code, I can’t tell. [import]uid: 12455 topic_id: 8754 reply_id: 31943[/import]

Well ive changed it so that you cant exit the game anymore. I am still having trouble making the game stop though.

If (playGame ~= false) then
the gamepeice follows the mouse drag

if(gamepeice.y <0) then
playGame= false;
print(“stuff”)
end

end

the problem im having now is that, the gamepeice will go out of the range to keep the game going, “stuff” will print in the terminal window, but the game wont stop. makes no sense whatsoever

[import]uid: 49677 topic_id: 8754 reply_id: 31949[/import]

I changed everything around. I figured this out

My ship starts at like 500,600. If the ship.y <600, then play ready = false and it will print what i tell it to

if i say If ship.y <400, and then move the above 400, it wont print and apparently isnt registering that the y has changed
how do i check for a change in the y, there for making the game stop? [import]uid: 49677 topic_id: 8754 reply_id: 31982[/import]

Runtime:addEventListener(“enterFrame”, your_fn_or_table)
Check the y coordinate in every frame.
– Advanced UI + Graph for Corona® | Website | Forum (https) | See: [import]uid: 11385 topic_id: 8754 reply_id: 32057[/import]