- Sep 6, 2021
- 740
- 1,678
I'm trying to include a simple script to allow the player to set the age of a character and I want to make it so they can only set it for 18 or higher.
I've used the code below and it works fine, up to a point. Any number between 10 and 17 will default to 18. A single 1 will also be returned as 18. Where it doesn't work is when a player inputs a single digit age between 2 and 9. Those slip through unchanged.
I've looked around and most of the similar examples I have seen are from Ren'py versions more then 4 years old.
Any suggestions that can fix this? Either make it properly parse ages "2-9" or force the player to input a minimum of 2 characters? I seem to recall Java had a min and maxlength function, but all i can find in Ren'py is the basic length one.
I've used the code below and it works fine, up to a point. Any number between 10 and 17 will default to 18. A single 1 will also be returned as 18. Where it doesn't work is when a player inputs a single digit age between 2 and 9. Those slip through unchanged.
I've looked around and most of the similar examples I have seen are from Ren'py versions more then 4 years old.
Any suggestions that can fix this? Either make it properly parse ages "2-9" or force the player to input a minimum of 2 characters? I seem to recall Java had a min and maxlength function, but all i can find in Ren'py is the basic length one.
Python:
$ mca = renpy.input("How old are you again?", default=18, length=2, allow="0123456789")
$ mca = mca.strip()
if mca == "":
$ mca="18"
if mca < "18":
$ mca = "18"
Last edited: