Hello, I’m working on a simple game where you guess a random number out of 1 - 100 and you only get 10 tries to guess it. Right now I’m attempting to add a GUI label, using js of course, and I am encountering a problem.
I have these two variables:
var guess:String;
var numberGen:int;
numberGen is the randomly generated number which is 1 - 100 and guess is the TextField:
guess = GUI.TextField(Rect(550,200,30,20), guess, 25);
Now here is where my problem is, even when parsing to an integer as you see here:
if (GUI.Button(Rect(535,230,60,40), "Accept")) {
if (numberGen == parseInt(guess)) {
if(guess < numberGen) {
print("Test");
}
if(guess > numberGen) {
print("Test2");
}
}
guesses--;
}
I still encounter this problem :
(Assets/WordGame.js(42,42): BCE0051: Operator '<' cannot be used with a left hand side of type 'String' and a right hand side of type 'int'.)
and
(Assets/WordGame.js(45,42): BCE0051: Operator '>' cannot be used with a left hand side of type 'String' and a right hand side of type 'int'.)
I don’t get why it’s still counting it as string even though I have the (if(guess < numberGen)) under the parse int.
I am a bit of a newbie when it comes to video game programming, especially since I have never learned js until a couple of weeks ago. Any help would be greatly appreciated.