I have finally done it! I have fixed the enemies code, which detect the flute being played near them. It took much longer than expected. This was due to the program engine GMS2 bugging out when I tried to add in a puzzle feature and a reset to failed inputs. In short the code was correct and ordered correctly, but it still didn’t work, unless I used a text box pop-up.
I have no idea what the issue was. I searched through all my code and tried countless fixes, but nothing worked, so I changed my design on how it should work.
The way I wanted it to work was to have a unique input for all guards and as soon as one input was incorrect, it would reset on that frame. Unfortunately this didn’t work, so I made it use a timer instead, which will resets the inputs after the timer hits 0.
Well enough of the explanation to why I changed the design and on to how I made it:
On the begin step on the Player, I added in detector, which will detect what guard is close by. Once detected it will send off the results to the guard object. The reason I didn’t check for the results in the guard was because, I would only be able to check if the object is nearby and not, which instance of that object is nearby.
Continuing on I wrote the code for the input check:
I got the number_pressed value from the player, after the flute animation plays the specific animation according to thee key pressed.
Once the key input is pressed it checks down the list, looking for the current sound it is on. Afterwards it compares the number_pressed value to the Sound_(1, 2 or 3) value and if they match it will play a sound and move on to the next input check. If all sound inputs are correct, it will make the guard fall asleep for 5.6s.
When the guard is asleep, they are safe to walk passed. The player is told in three ways that the enemy is asleep. The first is a snoring sound will play, which I got from here: https://freesound.org/people/monkslut/sounds/35208/. The second indication is Z above the enemies head:
The third way is by removing a timer, which I added it.
To add in the timer I first had to set it up, so I wrote this:
This sets up a timer for the guard and for the player. Once the timer hits 0, it will reset the inputs. Just with this I can reintroduce the same patterns, but reduce the timer, which will create another challenge with no new code needed.
To set up the visuals, I coded this in the player:
The code above sets up a timer to be drawn and then restricts access for the code to continue activating again, unless requested again.
The above code was used to create the cool-down timer visual. It uses an alarm, which triggers 100 times maximum before it is destroyed. Each time it triggers, it reduces the cooldownPercentage value by 0.02. This is so it will end up at -1, which means the start and the end point will have 0 pixels in between, meaning it won’t create anything.
When the cooldownPercentage value reaches -1 or below or the guard fall asleep, then the instance will detroy, meaning no more timer. Here is the timer in action:
I am extremely happy that this is finished and is better than anticipated IMO.
I am working on finishing off the first set of rooms and then I will update this blog post and soon afterwards I will create and release the game update V1.7.0 blog post.