Page 1 of 1

I have a new problem with an input...

Posted: Wed Oct 16, 2013 1:41 pm
by Himekuri
Hi I'm trying to write a code that responds to the player writing certain words
so far I have

Code: Select all

$ name = renpy.input("How are you today master?", length=20) or "Noname"    


if ((name != "Good") and (name != "Ok") and (name != "Fine") and (name != "Great") and (name != "k")):        
      jump bad
hide chihiro happy
show chihiro glad
c "That's good to hear!"      # %(name)s is old. you can use brackets to do it.

label bad:
c "Aw, well I hope things get better soon."
However if I write in "Good" it still shows me the text I get if i write "Bad" after it shows me the text I egt for the "good" option.
How can I make it so that the text you get for "bad" only shows up if you type anything else except the listed above?
sorry if its difficult to understand what I'm trying to say...

Re: Having trouble with using a certain input?

Posted: Wed Oct 16, 2013 2:38 pm
by jesusalva
Modified to RenPy 6.15:

Code: Select all

    $ name = renpy.input("May I please take your name?", length=20) or "Noname"    
    # I modified the variable to renpy 6.15

    if name != "emily":        # if name different from "emily"
      jump start

    c "Nice to see you again [name] ."      # %(name)s is old. you can use brackets to do it.
You using an older version of ren'py. The right would be update.
But the

Code: Select all

    if name != "emily":
should work fine in your version.

Re: Having trouble with using a certain input?

Posted: Wed Oct 16, 2013 2:58 pm
by Himekuri
jesusalva wrote:Modified to RenPy 6.15:

Code: Select all

    $ name = renpy.input("May I please take your name?", length=20) or "Noname"    
    # I modified the variable to renpy 6.15

    if name != "emily":        # if name different from "emily"
      jump start

    c "Nice to see you again [name] ."      # %(name)s is old. you can use brackets to do it.
You using an older version of ren'py. The right would be update.
But the

Code: Select all

    if name != "emily":
should work fine in your version.
Oh I see... thank you so much ! Also what would I need to write if I wanted more than one name to be accepted?

Re: Having trouble with using a certain input?

Posted: Wed Oct 16, 2013 3:22 pm
by jesusalva
Change

Code: Select all

    if name != "emily":
to

Code: Select all

    if ((name != "emily") and (name != "himekuri") and (name != "anna")):
That should do fine.

CAUTION! you've write the name in lower-case? then, if you write in upper-case, it is wrong. You are driven in start.

you can place "please, write in lower case" in the renpy.input text
OR
use:

Code: Select all

    $ name = renpy.input("May I please take your name?", length=20) or "Noname"   
    # I modified the variable to renpy 6.15
    $ name = name.lower()
That will work fine: lower() will change the input to lower-case. lower() is a python command, so it should work in older versions of ren'py.

I cannot grant that lower() will work 100% of times.

EDIT: changed "or" by "and" due "minor" errors.

Re: Having trouble with using a certain input?

Posted: Wed Oct 16, 2013 3:36 pm
by Himekuri
jesusalva wrote:Change

Code: Select all

    if name != "emily":
to

Code: Select all

    if ((name != "emily") or (name != "himekuri") or (name != "anna")):
That should do fine.

CAUTION! you've write the name in lower-case? then, if you write in upper-case, it is wrong. You are driven in start.

you can place "please, write in lower case" in the renpy.input text
OR
use:

Code: Select all

    $ name = renpy.input("May I please take your name?", length=20) or "Noname"   
    # I modified the variable to renpy 6.15
    $ name = name.lower()
That will work fine: lower() will change the input to lower-case. lower() is a python command, so it should work in older versions of ren'py.

I cannot grant that lower() will work 100% of times.
I'm sorry for coming with another problem but I changed it to

Code: Select all

 if ((name != "emily") or (name != "himekuri") or (name != "anna")):
but now regardless of what I enter it takes me back to start D:

Re: Having trouble with using a certain input?

Posted: Wed Oct 16, 2013 4:47 pm
by jesusalva
Oh, sorry, my error.
I've placed "or", but it should be "and". so the right is:

Code: Select all

 if ((name != "emily") and (name != "himekuri") and (name != "anna")):

Re: Having trouble with using a certain input?

Posted: Wed Oct 16, 2013 4:52 pm
by Himekuri
jesusalva wrote:Oh, sorry, my error.
I've placed "or", but it should be "and". so the right is:

Code: Select all

 if ((name != "emily") and (name != "himekuri") and (name != "anna")):
Oh! Thank you so much !! First day of doing this and I already learnt so much haha :mrgreen:

Re: Having trouble with using a certain input?

Posted: Wed Oct 16, 2013 4:58 pm
by Taleweaver
Wrong forum, buddy. Moving.

Re: Having trouble with using a certain input?

Posted: Wed Oct 16, 2013 11:55 pm
by Elmiwisa
There is a less painful way than typing (name!="something") every time. You can do:

Code: Select all

if name not in ["emily","himekuri","anna"]:
This is especially useful if there are too many allowed name that you cannot practically type out each one one-by-one. If there are very few number of allowed name, isn't it better if you just less the player choose one from a list instead of asking them to type? They most likely will get the name wrong and then end up having to retry many many times...

Re: Having trouble with using a certain input?

Posted: Thu Oct 17, 2013 1:22 pm
by Himekuri
Elmiwisa wrote:There is a less painful way than typing (name!="something") every time. You can do:

Code: Select all

if name not in ["emily","himekuri","anna"]:
This is especially useful if there are too many allowed name that you cannot practically type out each one one-by-one. If there are very few number of allowed name, isn't it better if you just less the player choose one from a list instead of asking them to type? They most likely will get the name wrong and then end up having to retry many many times...
The thing is, the game I'm creating is quite different. When you open the game you're kind of playing as a character talking to the game therefore the game asks a question and you type back.
That's why I need to have lots of options.

Re: Having trouble with using a certain input?

Posted: Thu Oct 17, 2013 1:38 pm
by xela
Himekuri wrote:
Elmiwisa wrote:There is a less painful way than typing (name!="something") every time. You can do:

Code: Select all

if name not in ["emily","himekuri","anna"]:
This is especially useful if there are too many allowed name that you cannot practically type out each one one-by-one. If there are very few number of allowed name, isn't it better if you just less the player choose one from a list instead of asking them to type? They most likely will get the name wrong and then end up having to retry many many times...
The thing is, the game I'm creating is quite different. When you open the game you're kind of playing as a character talking to the game therefore the game asks a question and you type back.
That's why I need to have lots of options.
He meant that

Code: Select all

if ((name != "emily") and (name != "himekuri") and (name != "anna")):
and

Code: Select all

if name not in ["emily", "himekuri", "anna"]:
do the same thing, only the latter is better readable and requires less typing. If you need to have a lot of options, checking membership in a container is better.

Re: Having trouble with using a certain input?

Posted: Thu Oct 17, 2013 1:48 pm
by Himekuri
xela wrote:
Himekuri wrote:
Elmiwisa wrote:There is a less painful way than typing (name!="something") every time. You can do:

Code: Select all

if name not in ["emily","himekuri","anna"]:
This is especially useful if there are too many allowed name that you cannot practically type out each one one-by-one. If there are very few number of allowed name, isn't it better if you just less the player choose one from a list instead of asking them to type? They most likely will get the name wrong and then end up having to retry many many times...
The thing is, the game I'm creating is quite different. When you open the game you're kind of playing as a character talking to the game therefore the game asks a question and you type back.
That's why I need to have lots of options.
He meant that

Code: Select all

if ((name != "emily") and (name != "himekuri") and (name != "anna")):
and

Code: Select all

if name not in ["emily", "himekuri", "anna"]:
do the same thing, only the latter is better readable and requires less typing. If you need to have a lot of options, checking membership in a container is better.
Oh I see !
oops :oops: