How to check conditions for a matching puzzle?

I’m making a game where after you solve a puzzle to unlock a drawer on one frame, it’s supposed to permanently start taking you to a different frame that displays that drawer open. The code I have runs without error but isn’t working as expected, so some help would be nice :slight_smile:

The puzzle consists of three boxes, each as their own clip with 3 symbols that can be cycled through. behind those boxes are colored squares whose colors can be set by clicking and dragging a color over to them. The goal is to match a particular combination of symbols and colors.

The code I made for checking the solution is as follows:

if (sq1.timeline.frames === 3 && sq2.timeline.frames === 1 && sq3.timeline.frames === 2 && project.rightBox == 3 && project.middleBox == 2 && project.leftBox == 1){
project.puzzleLock = 1;
}

sq1-sq3 refer to the clips containing the boxes with symbols to cycle through and is trying to check the frame number. project.leftBox and its ilk are trying to verify the value of global variables assigned to each of the colored squares in the following example code on the draggable colors:

for(var a of pink.clones){
if(this.hits(left)) {
left.activeFrame._children[0].fillColor = ‘#D940DD’;
project.leftBox = 3;
this.remove();
}
}

The following code is on a button in another frame/area, and meant to check whether the puzzle has been solved or not and take you to the correct frame/area.

if (project.puzzleLock==1){
gotoAndStop(29);
}
else{
gotoAndStop(28);
}

I am not sure where I am going wrong, and I must admit I have zero JS experience and have been working off of tutorials and a couple years of C from five years ago so I’m apologize if the problem is an obvious one :slight_smile:

you have a variable called a for each of the clones, but you don’t actually use it in the loop. could be a sign of a mistake in there. you might want to replace the 2 this's with a?

ahah, I got that bit from an example I found so it’s not my brainchild… I just assumed that “this” in this case was synonymous with using “a.” I changed it to “this” just now to see what would happen, but that didn’t seem to do anything new or break it which adds some weight to what I thought.

I probably should have clarified though, every aspect of the game works aside from the solution check part. So the click/drag/color change/symbol cycling all work but I can’t get the game to register when the correct combo has been input.

ah i think i found something. you might want to try using sq1.currentFrameNumber, etc to get each square’s frame.

Funnily enough, I had that originally but thought it wasn’t working so I tried alternative methods I found.

Going back to .currentFrameNumber and also catching a mistake in which frame all three boxes were looking for fixed that issue! I salute you :slight_smile:

The only problem now is that it only works in isolation from the color checking code… I had removed the three global variables in the 2nd half of the if statement to test the frame check fix but when I put them back it stops working.

Hey! I got the color check to work! Turns out in my testing, I had forgotten that the global variables are assigned only after the color object had been dragged into/hits the square, completely independent of the square’s actual color (I had been keeping the squares the same color to save time between tests so I wasn’t “activating” the squares).

It’s just the kind of problem that only happens in these kinds of tests… I had already planned on mix matching the colors to begin with so it shouldn’t happen in actual user play ;)

Thanks for thinking it all through with me!

1 Like