[SOLVED] 'If' statement, multiple names made to have the same reply in one code

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
Janfon1
Newbie
Posts: 6
Joined: Sat Dec 02, 2017 1:39 pm
Projects: "Catch and never release"
Deviantart: janfon1
Contact:

[SOLVED] 'If' statement, multiple names made to have the same reply in one code

#1 Post by Janfon1 »

Cheers!

I'll try to explain it to the best of my abilities, because I find the the formal way of describing it too confusing to me:

When the player chooses his name, I would like multiple names to be replied to the same way, be it because of similar meanings or changes in letters, say, Fireman and Firefighter, Ethan or Etan. The question is, how can I accomplish this without making a separate code for each name and instead summarizing all names to one code?

Here is a relevant fragment of the code I have right now:

Code: Select all

define na = Character("???")
define pl = Character("You")
define plchange = Character("[name]")


$ name = renpy.input("My name is...")
$ name = name.strip()

if name == ("Ethan" or "Etan"):
        $ name=("Ethan" or "Etan")
        scene face_evil
        na "Welcome to the family, son."
        pause.3
        scene face_default
        play sound prhuff
        na "Just kidding, I don't know my family."
        pause.2
jump after_give_name

label after_give_name:

na "Hm, seems cool."
na "Mine's Prosnorkulus."
plchange "Correct, my name should be changed now."
pl "Otherwise, here's my regular name."
In-game, for the name "Ethan" it plays the remaining dialogue. For "Etan", it skips to the next scene, but the name "Etan" displays correctly. I would like "Etan" to play the same dialogue as "Ethan".
Is there a way to cut down on the work or is there no other choice? Being able to do this would seriously make names more fun and advanced, say, six names that have the same reply!

Thanks for the help!
Last edited by Janfon1 on Mon Apr 23, 2018 3:54 pm, edited 1 time in total.
Laus alit artes

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: 'If' statement, multiple names made to have the same reply in one code

#2 Post by DannX »

I'm not sure I understand what you're trying to accomplish, but if you need to check the player's input against a list of names(strings), you could use, well, a list (a python list):

Code: Select all

default name = "You"

default ethan_list = ["Ethan", "Etan"]

label start:

    $ name = renpy.input("My name is...")

    $ name = name.strip()

    if name in ethan_list:
        scene face_evil
        na "Welcome to the family, son."

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: 'If' statement, multiple names made to have the same reply in one code

#3 Post by kivik »

To expand on DannX's code, I'd recommend you make the list lower cased, then do the check with:

Code: Select all

default ethan_list = ["ethan", "etan"]

...

if name.lower() in ethan_list:
Alternatively format the name with .title() to make it title cased.


If you want to have multiple lists and jump to different things, then you probably want to use a dict as well:

Code: Select all

define na = Character("???")
define pl = Character("You")
define plchange = Character("[name]")

label main_menu:
    return

define name_lists = {
    "ethan_list": ["ethan", "etan"],
    "fightmen_list": ["fireman", "firefighter"]
}

label start:
    python:
        name = renpy.input("My name is...").strip()

        for list_label, name_list in name_lists.iteritems():
            if name in name_list:
                renpy.jump(list_label)
    jump after_give_name

label ethan_list:
    na "Welcome to the family, son"
    jump after_give_name

label fightmen_list:
    na "A Fireman you say? Our family owe your family a great deal..."
    jump after_give_name

label after_give_name:
    na "Hm, seems cool."
    na "Mine's Prosnorkulus."
    plchange "Correct, my name should be changed now."
    pl "Otherwise, here's my regular name."

User avatar
Janfon1
Newbie
Posts: 6
Joined: Sat Dec 02, 2017 1:39 pm
Projects: "Catch and never release"
Deviantart: janfon1
Contact:

Re: 'If' statement, multiple names made to have the same reply in one code

#4 Post by Janfon1 »

Thank you for the help, this solved the problem for me! And to think it was just a matter organizing them in a list.
Laus alit artes

Post Reply

Who is online

Users browsing this forum: Alex