jeudi 30 juin 2016

If formula didn't work correctly

I have a script (game) and I wanted add simple customization but I have a little problem.

In script I have at the beginning:

var customText ='Text';

and later:

resultTxt = new createjs.Text();
resultTxt.font = "30px Arial";
resultTxt.color = "#333333";
resultTxt.text = customText;

I wanted now make different "customText" which depends on var "player.score". I tried to make something like this:

var customText ='Text';
var customText1 ='Text1';
var customText2 ='Text2';

and later:

resultTxt = new createjs.Text();
resultTxt.font = "30px Arial";
resultTxt.color = "#333333";
resultTxt.text = customText;
if (player.score < 2) {
resultTxt.text = customText1
} else if (player.score < 5) {
resultTxt.text = customText2
} else {
resultTxt.text = customText
}

And it didn't work, because always is showing "customText1" (not "customText" which is interesting for me). How can I make it good?

Aucun commentaire:

Enregistrer un commentaire