So today’s objective was the keypad I was going to do yesterday but got side tracked away from. It actually worked out for the best because during the course of the day I came up with the idea of how to achieve what I was after.
For the time being I set up a basic trigger area that I could just walk the player into to bring up the keypad. The keypad needed to be usable over and over so the trigger object (or initiate object) would pass over the required unlock code and the object that it is going to trigger on correct entry.
My initial concern with the keypad was the potential need for multiple sprites that I would have to reposition along the way (panel, all the buttons, the lcd display), but during my brainwave it was clear that that wouldn’t be the case. I can just draw everything needed over the top of the sprite. The buttons would highlight when the mouse is moved over them and the lcd panel is just a draw_text statement.
The hardest part turned out to be displaying the panel in the correct place and the button location coordinates. I had a brief brain-fart where the panel wasn’t coming up at all because I had used:
thinking that was all that was needed, but instead required:
Once that was resolved the rest of the code was pretty much straight forward; check the mouse coordinates when clicked to find out which button (digit) was pressed, update the LCD panel display. If the code is 6 characters long and wrong then display ‘INCORRECT’ and then reset the code for another try, the code is correct then remove the keypad from the screen, return control to player object and trigger the required object (a door in this case).
Everything works great. However, I will be increasing the size of the keyPad overlay because it is coming up just a little bit too small for the moment, but progress is progress so I’m happy.