我正在尝试创建一个if语句,当该分数高于当前的高分数时,该分数会很高。这是我的代码:
if scoreColorGame.score > scoreColorGame.highScore {
scoreColorGame.score = scoreColorGame.highScore
print(scoreColorGame.highScore)
}
每当我运行时,此
scoreColorGame.highScore
始终等于0。我已经检查过,并且if语句肯定在运行,但这是:scoreColorGame.score = scoreColorGame.highScore
不工作吗
最佳答案
您永远不会更改scoreColorGame.highScore。
尝试这个:
if scoreColorGame.score > scoreColorGame.highScore {
scoreColorGame.highScore = scoreColorGame.score // SET NEW VALUE FOR scoreColorGame.highScore
print(scoreColorGame.highScore)
}
关于swift - 当分数高于当前的高分时,做出高分?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44570078/