PDA

View Full Version : Input box problems


claire2903
05-07-2008, 01:12 AM
Have built a mini game and used the input box for typing in an answer to a question.

The input box works as i have an if statement. but if there is nothing in the box and the person clicks on the button, the person gets directed to the frame it should not saying Access granted.

I want it to go to the Access denied screen, but it wont.

do i have to include something else, the following is the code i have:

password = inputName


if (password == "the royal absolution" or "royal absolution") {
gotoAndStop (116);
} else {
inputStatus = "Access denied!" ;
}

Can anyone one help?

Noct
05-07-2008, 08:58 PM
Welcome aboard,

The problem is that you are trying to do an OR evaluation, but you aren't giving it the full argument on both sides of the or.

Using your above code, it would have to be more like this:

if ((password == "the royal absolution") or (password == "royal absolution")) {
gotoAndStop(116);
} else {
inputStatus = "Access denied!";
}


Were I going to write this myself, I would do it a bit differently as well.
You would probably want to include a case Switch to bypass any issues with the user capitalizing certain words and you might want to use a different variable name since password is a reserved word in flash.

I'd probably do it like this:

this.myBtn.onRelease = function() {
var myPass:String = String(this._parent.inputName.text).toUpperCase();
if ((myPass == "THE ROYAL ABSOLUTION") || (myPass == "ROYAL ABSOLUTION")) {
trace("Access GRANTED!");
} else {
trace("Access denied!");
}
};