Score help

hey everyone,

i need a little help with a score, i used a simple score using

local left = 2
local leftText = display.newText(left, 200, 20, native.systemFont, 24)
leftText:setTextColor( 0, 0, 0 )
leftText.x = 40
leftText.y = 430
leftText.rotation = 90
localGroup:insert(leftText)

and then i used

left = left - 1
leftText.text = left
to subtract one when the enemy “died”.
My problem is when i made a winner Boolean value and a retry button, and when winner == true then the retry button comes into view and when the retry button is touch then a couple things happen including left resetting itself to 2. But when the game restarts, left still equals 0 for a moment until the collision happens again where left switches from 0 to 1 and then the next collision it just goes to -1 and so on further messing up the game.

any help or suggestions?
or more explanation needed?

Thanks.

[import]uid: 113909 topic_id: 21558 reply_id: 321558[/import]

Use an if statement.

[lua]if left > 0 then left = left - 1[/lua]

That way it wont go below 0. [import]uid: 52491 topic_id: 21558 reply_id: 85466[/import]

It’d help to see more code for this to see why left is not changing back to 2. [import]uid: 10389 topic_id: 21558 reply_id: 85684[/import]

ps you can use the ‘lua’ codeword to display your code properly. It’s listed under the text box you type in here. eg:

[lua]local left = 2
local leftText = display.newText(left, 200, 20, native.systemFont, 24)
leftText:setTextColor( 0, 0, 0 )
leftText.x = 40
leftText.y = 430
leftText.rotation = 90
localGroup:insert(leftText)[/lua] [import]uid: 10389 topic_id: 21558 reply_id: 85685[/import]

(i know the code thing but i didn’t want to use it for multiple code strings, i have problems :slight_smile: )

i kind of fixed the problem but not really, i altered the way the retry button came into view.I made a new scene come up with the retry, menu and next button and so then i don’t really have to worry to much about the left score. But another problem i ended up with is when the retry button is touched, using the director i have it going back to the level1 scene but as soon as i go to the scene, it instantly goes back. I then saw it as a problem with how the restart scene opens up. So i proceeded to program the menu button to go to the working menu scene only to get a similar response, and on top of the scene going back the physics for the split second on the menu screen doesn’t seem to be working properly.
Any suggestions?

Thanks. [import]uid: 113909 topic_id: 21558 reply_id: 85716[/import]

Show is whatever code you are using for your restart button. Since the problem is occurring when you try to restart, thats the part we are going to need to look at to find whatever might be causing the problem. [import]uid: 69700 topic_id: 21558 reply_id: 85719[/import]

here is the retry button in the restarter scene

local rb = display.newImage("pictures/retry.png")  
rb.x = 150  
rb.y = 240  
rb.rotation=90  
localGroup:insert(rb)  
  
local function retry(e)  
 if e.phase == "ended" then  
 director:changeScene("level1","fade")  
 end  
end  
  
  
rb:addEventListener("touch",retry)  

and here is the code to get to the starter scene

local function win()  
 if (left == 0) then  
  
 winner = true  
 end  
 end  
local function choices()  
 if (winner == true) then  
  
 director:changeScene("restarter")  
  
 end  
 end  
Runtime:addEventListener( "enterFrame", win )  
Runtime:addEventListener( "enterFrame", choices )  
  

remember this isn’t just happening in this scene, when i go to the menu the same occurs,

many thanks.

[import]uid: 113909 topic_id: 21558 reply_id: 85806[/import]

problem solved, changed how changeScene was accessed.
[import]uid: 113909 topic_id: 21558 reply_id: 85921[/import]

cool! :slight_smile: [import]uid: 10389 topic_id: 21558 reply_id: 85924[/import]