Value error loop

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
Punderland
Newbie
Posts: 2
Joined: Tue Aug 22, 2017 4:31 am
Contact:

Value error loop

#1 Post by Punderland »

Hey guys, I tried to make an input for players to put in numbers. If they put in things other than number, it would loop back.

Code: Select all

label Calculator:
    $ inputNum1=renpy.input("Please enter a number")
    $ inputNum2=renpy.input("Please enter the second number")
    $ num1=float(inputNum1)
    if except ValueError:
        "Please enter a valid number"
        jump Calculator 
    $num2=float(inputNum2)
    if except ValueError:
        "Please enter a valid number"
        jump Calculator
However, how to detect whether the input can be converted into float? If it cannnot be converted, what code to put to detect it and loop back?

texi
Newbie
Posts: 14
Joined: Tue May 30, 2017 3:40 pm
Contact:

Re: Value error loop

#2 Post by texi »

Hi, I'm kind of an amateur to Renpy but i would have just done the whole thing in python.

Code: Select all

label calculator:
    python:
        inputNum1=renpy.input("Please enter a number")
        inputNum2=renpy.input("Please enter the second number")
        try:
            num1=float(inputNum1)
            num2=float(inputNum2)
        except ValueError:
            narrator("Please enter a valid number",interact=True)
            renpy.jump("calculator")

Punderland
Newbie
Posts: 2
Joined: Tue Aug 22, 2017 4:31 am
Contact:

Re: Value error loop

#3 Post by Punderland »

Thanks, gonna give it a try :)

Post Reply

Who is online

Users browsing this forum: No registered users