Create Combination Pin Padlock in Gamemaker

This gamemaker tutorial will teach you how to create a simple padlock with a pin code with a combination of three numbers from 0 to 9. You have to select the 3 correct numbers to unlock the padlock to win you prize.

Game Description: User has to enter correct 3 numbers to unlock the padlock to win the game. The padlock has a pin with 3 numbers from 0 to 9.

We need 4 objects: the padlock, 3 place holders for the hidden buttons which are used to press on that to pick the correct number.

Creating new gamemaker project then name it as NumPinPress or whatever you want.

Step 1: Creating 2 new sprites and Load images to them -- spr_Pin_Box, spr_Hidden_Button_96x96 --> set center for this sprite in order to let user click on the center of the objects later to increase the number.

Pix Box Padlock locked gamemaker img_Pin_Box_locked

Pin Box Padlock unlocked gamemaker img_Pin_Box_unlocked

Hidden Button 96 x 96  Gamemaker img_Hidden_Button_96x96


Step 2: Creating 4 objects: obj_Pin_Box, obj_btn_Num1, obj_btn_Num2 and obj_btn_Num3.

obj_Pin_Box will be the container of 3 obj_btn_Num1, obj_btn_Num2, obj_btn_Num3 hidden button. Plus, it will handle the correct or wrong pin that are entered by users.

obj_btn_Num1 --> users can click/tap on this object to select the correct first Pin number 1.

obj_btn_Num2 --> users can click/tap on this object to select the correct second Pin number 2.

obj_btn_Num3 --> users can click/tap on this object to select the correct third Pin number 3.

Step 3: Selecting spr_Pin_Box for obj_Pin_Box. In here, sprite spr_Pin_Box has two images, 1 for lock status red (sub image 0) and 1 for unlock status green (sub image 1). So, in the Create Event of obj_Pin_Box we will set the speed of the image equal 0 by adding the Action of Change Sprite and set the sub image to 0. This will keep the image of the lock is status red ( sub image 0)

Plus, we add the Code Actions for Create Event. We need two variable locked = 1; // means the gift box is locked. When we enter the correct pin, the locked will be equal to 0.

The second variable is pinnumber = "182"; // this is the preset correct pin number. User must enter the correct this number to unlock the padlock.

Step 4: in the obj_Pin_Box, we add the Step Event. Then we will add the Code Action for this Event.

The pin number is combination of three button numbers. If user press correct three numbers correct, they will win the game and make the sub image index of spr_Pin_Box of obj_Pin_Box become 1.

So, we need to check the user input every step to get the input padcode and compare it with the pinnumber - preset padcode - password of the box. Put those line of code to the Code Action.

pin = string(  + string( + string(;
  image_index = 1;
  image_index = 0;

Step 5: Now, we move to obj_btn_Num1. We add the Code Action for Create Event. We need the variable press = 0; // this variable will be increase 1 each time users press the button 1 and will be return to 0 when the max number reaches to 9.

We will add this line of code draw_set_valign(fa_middle); // to allow the text number will display middle of the button.

Next, we add the Left Release Event to obj_btn_Num1 object. Inside that, we add the Code Action and copy these line of code

    press = 0;

This code block will increase the press variable by 1 when the left mouse released and if the press variable reach the number 9, when user release the left mouse, the press will return 0 to let user start to enter the digit code again.

We also need the Draw Event for this object. Inside Draw Event, we add draw_text(x,y,string(press)); // this function will print the text number to the button. We need to convert to data type of press ( it is number type now) to string type to let the draw_text function print the text string to the screen. To do that we use string(number) function. x,y here is the position the text press will be display. Because we already set the spr_Hidden_Button_96x96 center so x,y will let the text be center of the button.

The Draw Event with draw_text() will draw the text number, it will clear the spr_Hidden_Button_96x96, we only use this sprite to visual the view to place the button to the room easier.

Also, we need to set the Depth of this button object to -1 to let it be front of the obj_Pin_Box so we can see the text number display over the obj_Pin_Box.

Step 6: Doing this step 5 again for 2 more objects obj_btn_Num2, obj_btn_Num3

Step 7: Placing the obj_Pin_Box, obj_btn_Num1, obj_btn_Num2, obj_btn_Num3 to the room. And try to run it to test the game.

Create Pin Padlock Gamemaker

Step 8: Pressing the buttons to select the correct combination to unlock the gift box. If you select the correct numbers the box will turn to green with unlocked status instead of the locked one.

If you feel it to hard or still can not build this gamemaker tutorials, you can download the source code here, try to run it and comeback here to check the instruction and explaination.


Fernando Dias

Great! ago, I wanted to make games like this one.

6/1/2016 4:08:53 PM
liam 12

i still can not build this gamemaker tutorials. Although your tutorial is really simple to understand.I will try again.

6/2/2016 4:00:11 AM

it seems that it is easy to make the same as it. i will do it follow your tutorial. Do hope that i will get the right way.

6/2/2016 4:13:16 AM
Toby Bboy

i created 2 new sprites. But when i set up their name ( just followed your tutorial), i really confused : - the first sprite : Spr_Pin_Box and the second sprite : spr_Hidden_Button Or the first sprite: spr_Pin_Box_locked and the second sprite: spr_Pin_Box_unlocked. Please make it clearly, thank you so much !

6/3/2016 4:53:34 AM

@Toby Bboy: i think you should set up their name follow the first option. I had done. Do hope that you can make it well. Just follow step by step of this tutorial

6/3/2016 6:53:56 AM
Toby Bboy

@Nathan: Thank you for your advice. i will try again!!

6/3/2016 7:01:13 AM

i still can not build this gam.So i think i will download the source code , try to check the instruction and explaination again.

6/3/2016 8:44:57 AM