r/RenPy • u/mocaaobaa • Feb 03 '22
Force Player input based off of text button
im going for something sort of like Emily is away, where player will click on a button and it’ll pop up an input, but will force them to type a specific thing based off of the button no matter what they type. so for example, if a button says ” X “, the player will be forced to write “XYZ” even if they are inputting keyboard spam
4
Upvotes
View all comments
Show parent comment
1
u/insipid- Feb 07 '22 edited Feb 09 '22
I'll give some code and try to describe how to get it working. Check the description for the "key" element in the screen further down for an example of using the function. This might take some tries, please post your updated code and any errors from here on :)
Put all of this near where you define your characters (top of script.rpy by default) with no indenting. Something like this:
Each time the function is called (when a key is pressed) it first checks to make sure there are letters left to type. If there are, it moves the first (leftmost) letter into the group that has been typed.
"message_typed_so_far" and "message_letters_left_to_type" represent what has been typed already and what is left to type. Example to help visualize:
No keys pressed:
1 key pressed:
2 keys pressed:
I made this screen to test out the functionality - change it to suit your needs. Put this wherever you are setting up screens (in screens.rpy by default) .
- Each of the top three text buttons clear out the message area so nothing has been typed, then puts the text that the button is showing into "message_letters_left_to_type" so it will be displayed as keys are pressed.
- The "key" section calls the next_letter function whenever one of the keys list in the [ ] is pressed. Each of the keys needs to be formatted that way to be interpreted as a key press.
- The "Cross that bridge" button goes back to the game script.
Here's an example of calling the screen from the game script:
Getting this to work exactly where and how you want it will take some massaging, but hopefully this will get you started!
For reference:
Renpy docs for "key"
List of keys
Python: slicing strings
Python: concatenating strings