I have a scene “gameover.lua” that is open with showOverlay, and in scene:create I want to show or not a newText according to the case.
For this I try multiple solutions, but when I put the code so that it does not see , the text is not seen in any case.
e.g.:
local newHighScore = false if currentScore \> currentHighScore then newHighScore = true end local newHighScoreLabel = display.newText("New high score!!", 100, 100) if (newHighScore) then newHighScoreLabel.alpha = 1 else newHighScoreLabel.alpha = 0 end sceneGroup:insert(newHighScoreLabel )
This not show the newText.
If I coment --newHighScoreLabel.alpha = 0 then show it
But in all solutions when I write the part to hide or make text “” in any case show me the text.
and I have another code in true part and it works perfectly.
insert: print (newHighScore) before the last if statment. and check console if its getting true or false. i suspect your getting false, so the problem if there are any is the currentScore that is not triggering to true. print also before the first if:
print (currentScore, currentHighScore)
prints helps alot when you are debugging. try them and you will find your error (if there are any). this part of the code you are showing us is correct.
Carlos is right, and beyond that, you may want to change the text value of a singular newText object for the high score if the score is exceeded, rather than creating a new one each time.
insert: print (newHighScore) before the last if statment. and check console if its getting true or false. i suspect your getting false, so the problem if there are any is the currentScore that is not triggering to true. print also before the first if:
print (currentScore, currentHighScore)
prints helps alot when you are debugging. try them and you will find your error (if there are any). this part of the code you are showing us is correct.
Carlos is right, and beyond that, you may want to change the text value of a singular newText object for the high score if the score is exceeded, rather than creating a new one each time.