2017-06-15 93 views
0

我試圖創建一個if語句,當得分高於當前最高分時得到高分。這是我的代碼:當分數高於目前的高分時,做出高分?

if scoreColorGame.score > scoreColorGame.highScore { 
     scoreColorGame.score = scoreColorGame.highScore 
     print(scoreColorGame.highScore) 

    } 

每當我跑這scoreColorGame.highScore總是等於0。我已籤,如果語句是肯定運行,但這樣的:

scoreColorGame.score = scoreColorGame.highScore 

不工作?

回答

0

你永遠不會改變scoreColorGame.highScore。

試試這個:

if scoreColorGame.score > scoreColorGame.highScore { 
     scoreColorGame.highScore = scoreColorGame.score // SET NEW VALUE FOR scoreColorGame.highScore 
     print(scoreColorGame.highScore) 

    }