Page 1 of 1

[SOLVED] Using player input as points?

Posted: Mon Jul 19, 2021 10:08 am
by ZeAwesomeHobo
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...?

Re: Using player input as points?

Posted: Mon Jul 19, 2021 10:41 am
by Jackkel Dragon
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

Re: Using player input as points?

Posted: Mon Jul 19, 2021 11:51 am
by ZeAwesomeHobo
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()