Problem with if() else command

When I press 1 it works to turn it on but then it doest react if I press 1 afterwards. I don’t know whats going on with it.

if (this.app.keyboard.wasPressed(pc.KEY_1)) {
    if (this.sas = 'off') {
        this.sas = 'on';
        this.sasIndicator.element.text = this.sas;
    } else if (this.sas = 'on') {
        this.sas = 'off';
        this.sasIndicator.element.text = this.sas;
    }
}

Hi @Maximos_Finley,

When checking values in your if statements, you want to use == or ===, otherwise a single = will always return true and also change the value of your this.sas property.

if(this.sas === 'off'){
2 Likes