I have a problem with making ren'py analyze an user input

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
User avatar
enrap93
Newbie
Posts: 6
Joined: Tue May 17, 2016 5:08 pm
Projects: kiss/kill the oni
Deviantart: enrap93
Location: winterfell
Contact:

I have a problem with making ren'py analyze an user input

#1 Post by enrap93 »

hi, here I am again with another doubt, this time I'm not making a game, instad I'm maing a software to make the user learn some mathematic formulas... I decided to make it in ren'py because I have spent more time with this than others software-making programs...

so, wathever, i was making this program and i dont know what to do here (i simplified the formula by the way XD)...

Code: Select all

                
                    $ responce1 = renpy.input("how much is 2 + 2?")
                    if responce1 == "2 + 2": 
                        "Correct, the responce is [responce1]."
                    
                    else:
                        while responce1 != "2 + 2":
                            $ responce1 = ""
                            $ responce1 = renpy.input("incorrect, how much is 2 + 2?")
                    "Correct, the responce is [responce1]."
the problem when i do this is that the program keep saying that the respond is wrong, i keep typing 4, but the porgram keep saying is wrong...

so, yeah thats all, I have a week trying to correct this, but i can't do anything, so I really need your help...

User avatar
Karl_C
Veteran
Posts: 232
Joined: Sun Mar 31, 2013 6:18 am
Contact:

Re: I have a problem with making ren'py analyze an user inpu

#2 Post by Karl_C »

"2 + 2" is a string, not an int or float value: Parse String to Float or Int

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: I have a problem with making ren'py analyze an user inpu

#3 Post by Imperf3kt »

Just pointing out that "responce" should be "response"
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

renpic
Newbie
Posts: 19
Joined: Sat Apr 08, 2017 1:07 pm
Location: Europe
Contact:

Re: I have a problem with making ren'py analyze an user inpu

#4 Post by renpic »

enrap93 wrote:hi, here I am again with another doubt, this time I'm not making a game, instad I'm maing a software to make the user learn some mathematic formulas... I decided to make it in ren'py because I have spent more time with this than others software-making programs...

so, yeah thats all, I have a week trying to correct this, but i can't do anything, so I really need your help...
You can try this snippet of code:

Code: Select all

    $ response1 = renpy.input("how much is 2 + 2?")                             
                                                                                
    while response1 != "4":                                                     
        $ response1 = renpy.input("incorrect, how much is 2 + 2?")              
                                                                                
    "Correct, the answer is [response1]."
Note that here the answer is not converted back to a number, but used as a string. So the same code should work with a question that requires a textual answer. For example:

Code: Select all

    $ response2 = renpy.input("Who is the superhero who fights the Joker?")     
                                                                                
    while response2 != "batman" and response2 != "Batman":                      
        $ response2 = renpy.input("Incorrect, who is the superhero who fights the Joker?")
                                                                                
    "Correct, the answer is [response2]."
When multiple right answers are possible, you have to account for them. Here we accept both a lowercase answer, and a capitailzed one.
(In this case, a better way would be to downcase the answer; but I wanted to show how to accept more than one answer, as it could be useful to you later on.)

User avatar
enrap93
Newbie
Posts: 6
Joined: Tue May 17, 2016 5:08 pm
Projects: kiss/kill the oni
Deviantart: enrap93
Location: winterfell
Contact:

Re: I have a problem with making ren'py analyze an user inpu

#5 Post by enrap93 »

thank you all very much for your responses!!!
Karl_C wrote:"2 + 2" is a string, not an int or float value: Parse String to Float or Int
indeed, that was my problem, i have first to convert the words thatat the user have writed in a int or a float, now the program workds perfectly.


Imperf3kt wrote:Just pointing out that "responce" should be "response"
yes, sorry XD I'm still having problems in writing english.


and thanks to "renpic" too, for your response.

now I can keep working in this program again. Thank you very much to you all again.

Post Reply

Who is online

Users browsing this forum: Google [Bot], WladekProd