It's a simple 'Have Key-Door unlocked/ No Key- Door locked' Boolean thing but whenever I collect the key and try to use the door it still won't open and plays the locked sound, and I can't figure out why.
var keyCollected: Boolean = false;
var doorOpen: Boolean = false;
keyclick_btn.buttonMode = true;
keyclick_btn.addEventListener(MouseEvent.CLICK, releasekey);
function releasekey(e: Event): void {
keymc.gotoAndPlay(1);
keyclick_btn.visible = false;
keymc.visible = true;
keyCollected == true;
}
doorhandle_btn.addEventListener(MouseEvent.CLICK, licklock);
function licklock(e: Event): void {
if (keyCollected == false) {
var lockSound: Lock = new Lock();
lockSound.play();
}
}
doorhandle_btn.addEventListener(MouseEvent.CLICK, open)
function open(e: Event): void {
if (doorOpen == false) { // if the door hasn't been opened yet
if (keyCollected == true) {
doorOpen = true;
trace("open");
doorOpenmc.visible = true;
doorOpenmc.gotoAndPlay(1);
}
}
}
In your
releaseKey
function you have an extra=
in the following statement:Which just evaluates to a boolean and does nothing. If you change it to
keyCollected = true
, the if statement in theopen
function should evaluate to true.