Hello. I have a question regarding adding a sequence of button presses in a widget. I want to create a keypad door, that opens a widget when you press ‘e’ on it. Managed to do it this far. Now, I have invisible widget buttons that respond to the keypad’s buttons, but I have no idea how to script the whole thing to work. I want the following to happen:
When you press 1 2 4 7 in this sequence, the door unlocks. If you press any other keys in between those, it resets.
Thanks.
how do you do the number input? you could give the door a “enable input” function for the controller that presses E.
make 4 bools.
check whether first input is “1” if yes make the bool “true”.
do that with the rest of the bools aswell. ( 2, 4, 7 )
after last input make an enter input or something and make a branch and pin in an AND for the 4 bools. if all bools are true, execute the door open function.
Sorry, but I didn’t quite understand. Mind making it a bit more detailed? Thanks.
its hard to give you a tutorial if I don’t know how the keypad exactly works that’s why I asked you how you make your input because you said something about invisible widgets etc.
There’s a picture of the widget :
There’s a button without border and background on top of each number.
For example, where it says ‘1’ we have a button that corresponds to ‘Button_1’ for blueprint purposes. We’ve deleted the border and background of those buttons so they are invisible to the player. How do we blueprint this though for a sequence of correct button presses though?
Thank you again!
There are several ways of doing his, but I bet there’s a really really smart way using logic and maths. Entrants please!
I’d probably have an int for the number index you’re at which advances if you press the right button. Then use a switch on int to cycle through each keypress check. This - by the way - is the opposite to the ‘really really smart way’.
If all else fails you could bruteforce it.
Each time a button is pressed you set a bool assigned to that number to “true” and then you check if it’s part of the sequence. If it’s not then you set everything to false and play a “ZOINK!” sound.
Bruteforce Example:
- Press button 1
- 1 is set to true
- Press button 2
- 2 is set to true
- Press button 4
- 2 is set to true
- Press button 7
- 7 is set to true
- Have a function that checks if 1, 2 4 and 7 are true and proceed
Of course you’d also want to check if the order is true.
Then again, this is also the really really stupid way of making things, but in the end it would do the job.
Slightly Clever Example:
A better way would probably to create a string variable and append each number to it on button press and then check if the string in the end equals your set passcode. If it doesn’t you just clear the string variable.
I bet someone more knowledgable than me could come up with an even better solution.
EDIT:
And now I feel stupid.
That’s what you get when you leave tabs open for too long… example is basically my “clever” approach just even better and with an actual screenshot! Nice work!
It’s happened to me before, haha.
Thank you all guys! We’ll try 's method first, see if it works, and if we have any question, we’ll ask them Thank again!
I am being stupid, but I still can’t get it working, I just changed to destroy widget… Thanks a lot.
Each button would have it’s own event, or call a function but pass in it’s own ‘token’. So button 1 would append “1”. Button 8 would append “8”. If you just call ‘button’ for every key, this won’t work.
If at any point the input string is equal to your code, the player put the right sequence in. You can show an animation for completing it, or just remove the widget and unlock the door. If not, you check if the code starts with the current sequence- if it doesn’t, you’d want to play an effect, kick the player out of the keypad UI, or just reset the code.
I didn’t understand exactly what you meant, sorry, can you explain it to a non-programmer. Thanks.
- Copy my first image.
- Copy the ‘button pressed’ event (and all attached to it) for every button
- For every button event, change the number in ‘Make literal string’.
- Ensure you do not have duplicates of the ‘open’ and ‘reset’ events.
- Have something be triggered off ‘open’ and ‘reset’ events- open would be triggered when the code worked, reset if the code is ever incorrect.
Hello again, sorry for the late respond, I was trying it. I know I’m being a real pain, but this is so far what I’ve got.
http://postimg.org/image/5sap8kfuz/
http://postimg.org/image/ixbyq2onf/
http://postimg.org/image/hhwlw4jez/
I made different events for each button, different inputs on the literal strings, but I can’t yet get it working. Again - sorry for being a pain.
Okay I build a rough sketch of how I’d do it:
First place all of your nodes into a function. Just select everything, rightclick and “collapse to function”.
Then you make a custom event that you hook up to each button like this:
The custom event needs a string input:
And inside the function it’s hooked up like this:
Is that clear enough now?
Alright, now I feel extremely stupid… 's a picture :
For the sake of making it all easy to see, I removed the function, and let the code be visible at all times. Now, if I entered the right code, there should be a ‘Door Opened’ text appearing, but it doesn’t show up. I’ve spent the last 2 days trying to make it work, but it just doesn’t happen… What am I doing wrong?!
It doesn’t appear that you’re setting the code to 1374.
Don’t know why I didn’t spot it sooner.
Oh my god, it finally works! Thank you so much. Wooh…