AS3:如何使用 if 语句检查变量?

AS3: How can I check a variable with an if statement?

所以这段代码对我来说似乎应该 运行 顺利,但我似乎无法使用 if 语句来检查分数然后使按钮出现。有什么建议吗?

//Score variable
var score = 0;

//Multiplier variable
var multiplier = 1;

//Point Scorer
function PointScore() {
score = score + multiplier;
}

//update score function
function updateScore() {
txtPlayerScore.text = "Smash Points: " + score;
}

//Score Text
txtPlayerScore.text = "Smash Points: " + score;

//Make Power Up button invis
btnPowerUp.visible = false;

//If the score is 50 the button is now visible
if (score == 50){
btnPowerUp.visible = true;
}

//Power Up button
btnPowerUp.addEventListener(MouseEvent.MOUSE_DOWN, UpClicked);

function UpClicked (e:MouseEvent){
multiplier = 5;
}

根据您发布的代码,if 检查毫无意义,因为它会在您将分数设置为 0 后立即发生。您想在每次更改时检查分数,例如将其放在 PointScore() 功能。此外,您可能希望它是 if(score >= 50) 而不是 == 50,否则如果分数超过 50,它不会触发条件。

function PointScore() {
    score = score + multiplier;
    checkScore();
}

function checkScore(){
    if(score >= 50){
        btnPowerUp.visible = true;
    }
}