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.
-
HiddenLife
- Newbie
- Posts: 13
- Joined: Wed Sep 09, 2020 8:10 pm
-
Contact:
#1
Post
by HiddenLife » Wed Sep 07, 2022 11:20 am
Hi everyone.
I'm trying to get the age of a character modified by the user with an input in a screen.
Here's the code:
Code: Select all
screen E_age:
input default "[Eage]":
pixel_width(500)
value VariableInputValue("Eage")
I want that the variable Eage to change according to what the user type. I know this code would work if I'm working with strings, but, with integers, it wont work.
Somebody please can help me?
-
Ocelot
- Eileen-Class Veteran
- Posts: 1882
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
-
Contact:
#2
Post
by Ocelot » Wed Sep 07, 2022 12:41 pm
There are two possibilities:
1) Let input variable be string and convert to int afterwards.
2) Create your own InputValue subclass and do conversion on the fly.
< < insert Rick Cook quote here > >
-
HiddenLife
- Newbie
- Posts: 13
- Joined: Wed Sep 09, 2020 8:10 pm
-
Contact:
#3
Post
by HiddenLife » Thu Sep 08, 2022 6:31 am
Ocelot wrote: ↑Wed Sep 07, 2022 12:41 pm
There are two possibilities:
2) Create your own InputValue subclass and do conversion on the fly.
I have absolutely NO idea how to do that.
-
Ocelot
- Eileen-Class Veteran
- Posts: 1882
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
-
Contact:
#4
Post
by Ocelot » Thu Sep 08, 2022 6:49 am
Following guide on
https://www.renpy.org/doc/html/screen_p ... InputValue
it will look somethiong like:
Code: Select all
# does not do error checking, restrict input to digits only
# Does not support non-default stores
class IntegerInputValue(InputValue):
def __init__(self, var):
self.var = var
self.default = True
def get_text(self):
return str( getattr(store, var) )
def set_text(self, text):
setattr(store, var, int(text))
def enter(self):
return getattr(store, var)
# . . .
input value VariableInputValue("Eage") allow "0123456789"
It should work, unless I made a typo somewhere.
< < insert Rick Cook quote here > >
Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot]