Door that can open with codes

How do I…

Make a door that unlock by entering code from 0 to 9 with buttons.

Create number variable

And check if value of variable = your code here

Each button enters its number into a text box. When the text of the textbox equals the code, set the Boolean of codeEntered to true, and if that Boolean is true, unlock the door.

You might need a pop-up menu for this, I’m thinking, but that’s pretty easy to do.

i mean with this keypad
download

panel sprite buttons, also

Sorry sorry not number variable

Make TEXT variable
Make 9 panel sprite objects or as many as you need to cover all buttons
And now in events you do like

Condition
Button 1 is pressed
Trigger once

Action
Change text variable ADD 1

Another event

Condition
Button 0 is pressed
Trigger once

Action
Change text variable ADD 0

And so go on for every possible button

Now you check if that variable = some value
For example if variable is equal to “04258”

Try it

Now, how do i limit the input so it will be only 4 numbers?

To event that add to variable new characters
Add new condition
Find compare two numbers
In 1st expression you type
StrLength(your word here or variable holding that word) less than
And in second expression StrLength(variable to which you input text)

For example

This way if current input is longer than output text then i won’t be able to add any new character to current input

Where just to be clear
Current input is text to which i add characters
And output text is something that holds correct word
I could write there 5

And now i could get max of 6 characters in current input
And nothing more

wait a minute, i realized i made a mistake.
Its supposed to be output, so… im sorry for that
Screenshot (150)

Me no understand?
zzzzzzzzzzzz

The X thing is the number that is not supposed to be showed after the first 4 numbers

C - Clear all input
< - Remove last digit from input
0-9 - Add input

Top text is current input
Bottom text is previous input

CurrentInput var CANNOT have more than 4 characters (or more likely will not add new characteers after it is 4 characters long)
So after it is 4 characters long you need to either press C or <

PreviousInput will remove 1st character on the left and add new one on the right if its longer than 4 digits

This made me even more confused

Which part confused you?

the string one, but that made me find simpler way to put the limit on output
Basically, just use variable on the buttons and make it add variable limit
if the limit reach over 3, you cannot type again.
Thanks for the help!

SubStr (Your string here or text variable , from what position to start from left , how long portion to take)

So we have word carrot
We go with
SubStr ( carrot , 0 , 2)
Then we are starting from 1st position from left and we want t 2 characters so we get ca
IF we go with
SubStr ( carrot , 0 , StrLength(carrot) - 1)

StrLength( your string or text var here )
Will give you number of how many characters it have
So in case of StrLength(carrot)
You will see 6 since word carrot have 6 digits
and since we are going with -1 it will cut off last character and we will get carro

SubStr (carrotisugly , StrLength(carrotisugly) - 4 , 4 )
Again StrLength returns number of character string contains
So in this case carrotisugly we get 12 but we go with -4 so we move starting position to -4 from right side and we want to display 4 characters from that position in this case we get ugly
So if we now change carrotisugly to carrotisuglybleh

We will get bleh instead
Since it always displays last 4 characters

But if you found your way around it

So like i said i left you with 2 choices
One to only allow to input 4 characters and then require user to erase at least one to input new one or all of it

Or to always display last 4 characters no matter what is the length of text

But if you did it your way then i guess you are fine

Well, I used a different solution for this.

You can check the label of these buttons in events, right? And you have a text object to display the code.

First, add every button to an object group and call it [Buttons]

Then create an event like that;

[Buttons] is pressed
→ Change the text of [Text]: Add [Buttons].LabelText()

So it will add the label of the button you pressed to the displayed text.

And to count the number of displayed digits, you can create a variable called [Digits] in your Text object and everytime player presses a button, add 1 to it. So your event should look like this,

[Buttons] is pressed
→ Change the text of [Text]: Add [Buttons].LabelText()
→ Change the variable [Digits] of [Text]: Add 1

And you can clear it when it reaches 4.