Score help

8 replies [Last post]
boxie
User offline. Last seen 1 week 2 days ago. Offline
Joined: 27 Dec 2011

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.

Replies

peach pellen's picture
peach pellen
User offline. Last seen 1 day 13 hours ago. Offline
Staff
Joined: 12 Apr 2011

Use an if statement.

if left > 0 then left = left - 1

That way it wont go below 0.

WauloK's picture
WauloK
User offline. Last seen 3 days 7 hours ago. Offline
Joined: 21 Oct 2010

It'd help to see more code for this to see why left is not changing back to 2.

WauloK's picture
WauloK
User offline. Last seen 3 days 7 hours ago. Offline
Joined: 21 Oct 2010

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)

boxie
User offline. Last seen 1 week 2 days ago. Offline
Joined: 27 Dec 2011

(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.

ertzel
User offline. Last seen 7 weeks 15 hours ago. Offline
Joined: 15 Jun 2011

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.

boxie
User offline. Last seen 1 week 2 days ago. Offline
Joined: 27 Dec 2011

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)

and here is the code to get to the starter scene
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 )

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

many thanks.

boxie
User offline. Last seen 1 week 2 days ago. Offline
Joined: 27 Dec 2011

problem solved, changed how changeScene was accessed.

WauloK's picture
WauloK
User offline. Last seen 3 days 7 hours ago. Offline
Joined: 21 Oct 2010

cool! :)

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.