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.
-
ZeAwesomeHobo
- Newbie
- Posts: 4
- Joined: Mon Jul 19, 2021 12:10 am
-
Contact:
#1
Post
by ZeAwesomeHobo » Mon Jul 19, 2021 10:08 am
I'm trying to save player input as persistent data that can later be used in an if clause. Reading through a ton of threads, I found out how to save the player input--
Code: Select all
q "How tall are you in centimetres?"
python:
pheight = renpy.input("How tall are you in centimetres?", exclude='{QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm}', length=3)
pheight = pheight.strip() or __("170")
persistent.playerheight = pheight
renpy.save_persistent()
$ persistent.playerheight = [pheight]
But when trying to use the variable as points in an if clause, it ignores it, or makes the value impossibly high.
Code: Select all
label start:
"..."
call heightcheck
"..."
label heightcheck:
if pheight <= 170:
"You are [pheight]cm. You are below 170cm."
elif pheight == 170:
"You are [pheight]cm. You are 170cm."
elif pheight >= 170:
"You are [pheight]cm. You are above 170cm."
return
Even if the player input is "1," the heightcheck label will still take the "elif pheight > 170" path. Additionally, when the game is restarted and ran through with persistent data, the [pheight] value is presented as "[u'1']" in the textbox rather than just the entered value. I'm not one to assume, but it seems as though player input is not saved as a pure number value and cannot be used as points in this way...?
Last edited by
ZeAwesomeHobo on Mon Jul 19, 2021 1:24 pm, edited 1 time in total.
-
Jackkel Dragon
- Veteran
- Posts: 269
- Joined: Mon Mar 31, 2014 7:17 pm
- Organization: Nightshade, Team Despair
- itch: jackkel-dragon
- Location: USA
-
Contact:
#2
Post
by Jackkel Dragon » Mon Jul 19, 2021 10:41 am
It looks like you're saving as a string, so it's doing string comparisons in most cases. Not sure why it's not just giving errors, really.
You may need to cast the string to an integer with
Code: Select all
int("100") ## converts "100" to 100
Main Website
Includes information about and links to many of my current and past projects.
Major Game Projects
[
Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[
Team Despair] Corpse Party D2 series
-
ZeAwesomeHobo
- Newbie
- Posts: 4
- Joined: Mon Jul 19, 2021 12:10 am
-
Contact:
#3
Post
by ZeAwesomeHobo » Mon Jul 19, 2021 11:51 am
Thank you so much! I had to do some quick research into integers but it works!
Code: Select all
python:
pheight = renpy.input("How tall are you in centimetres?", exclude='{QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm}', length=3)
pheight = pheight.strip() or __("80")
pheight = int(pheight) ##Adding this line fixed the issues.
persistent.playerheight = pheight
renpy.save_persistent()
Users browsing this forum: Google [Bot], Majestic-12 [Bot]