Text input that only allows numbers?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
twodee
Newbie
Posts: 12
Joined: Tue May 08, 2018 4:30 pm
Contact:

Text input that only allows numbers?

#1 Post by twodee »

In my game, each day, the player has to enter an integer. Any integer they put will give results, though some will give different results than others (like, if they put 0-50, a different thing happens than when they put in 51-100). I believe I know how to code the results, but I don't know how to do a specific text input that forces the player to only put integers (unless I manually do it, number by number). How should I do this?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Text input that only allows numbers?

#2 Post by Ocelot »

The standard input screen is very customiseable, as documentation tells us:
https://www.renpy.org/doc/html/input.html#text-input

In your case you want something like:

Code: Select all

$ renpy.input(allow="0123456789")
< < insert Rick Cook quote here > >

twodee
Newbie
Posts: 12
Joined: Tue May 08, 2018 4:30 pm
Contact:

Re: Text input that only allows numbers?

#3 Post by twodee »

Thanks! One more question though: How do I make the if statements relevant to the number the player inputted? Ex: If the player enters a number in between 100 and 249, the game jumps to a certain label.

alee
Newbie
Posts: 7
Joined: Sat May 05, 2018 7:17 pm
Contact:

Re: Text input that only allows numbers?

#4 Post by alee »

hi!

You can use conditional statements to do this! There's some good info here:
https://www.renpy.org/doc/html/quicksta ... statements

something like this might work for you:

Code: Select all

$ number = renpy.input(allow="0123456789"
if number >= 100 and number <= 249:
	jump label1
else:
	jump label2

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Text input that only allows numbers?

#5 Post by kivik »

Tip, Renpy uses Python condition statements, and Python can do this with conditions:

Code: Select all

if 100 <= number <= 249:
    jump label1

twodee
Newbie
Posts: 12
Joined: Tue May 08, 2018 4:30 pm
Contact:

Re: Text input that only allows numbers?

#6 Post by twodee »

Thank you both for the help! It works now :D

Post Reply

Who is online

Users browsing this forum: Google [Bot]