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.
It'd help to see more code for this to see why left is not changing back to 2.
ps you can use the 'lua' codeword to display your code properly. It's listed under the text box you type in here. eg:
1 2 3 4 5 6 7 | 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) |
(i know the code thing but i didn't want to use it for multiple code strings, i have problems :) )
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.
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.
here is the retry button in the restarter scene
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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 ) |
many thanks.
problem solved, changed how changeScene was accessed.
cool! :)
Use an if statement.
if left > 0 then left = left - 1That way it wont go below 0.