Create a Text-Based Code Lock

Hi everyone!

I’m trying to create an educational game for my students. To that end, I’m trying to incorporate ways for students to answer questions in order to advance further in the game. Right now, I’ve been using the text input event to have students put in correct answers and open things like doors, chests, lockers, etc. I’ve managed to get it so that the items/animations change once they put in the correct “code” (right now I’m just using numbers; hoping to eventually add text in the future), but I have yet to find a way to code in a “wrong input” without having to create thousands of different events for each individual number code. Is there a way for me to create a range of numbers using the text input event that all have the same result? For example, right now when I type “1234”, the door opens after finishing the code. But nothing will happen if I type in “0001” or “9999” without having to create individual events for each of these numbers.


  1. Wanting to create a text-input code that unlocks things
  2. Created a code that works using the text-input event, but haven’t figured out how to make incorrect codes without creating an event for each of the possible incorrect codes.
  3. Hoping to find a way to create just a few events that calculate the range of multiple incorrect inputs.

Thanks for the help!

I’m not sure if I understand. To check if it’s correct you use =“1234”. If you want to check for incorrect answers, you could use ≠ “1234” (not equal to). Unless you mean something else.

Edit: the not equal line is a bit tricky. With the trigger once it’s only going to trigger once, no matter how many ways a wrong answer is typed. But without the trigger once it will trigger on every frame. It only triggers again if the correct answer was typed and then an incorrect. Which wouldn’t be needed. You would probably want to pair it with a submit button and check it then if you aren’t already doing that, otherwise, you would have to save the previous value and compare it to the present to identify a change. I’m probably over-complicating things.

Sorry for the confusion! Yes, I tried the reverse equal and it would activate on every single frame, so a submit button would definitely help. I hadn’t even thought about that! Is there a premade event that I could use to set that up? I’ve only been using this for about two weeks, so I still don’t know very much about the program…

You can add a button (panel sprite) object and then use the 2 events to check it under the click condition. This use the Blue Button. There are a lot of different styles.

Maybe you might want to do some more tutorials and look at templates to get a better understanding of Gdevelop.

1 Like