Inserting multiple names into dialogue [SOLVED]

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
Soliloquy
Regular
Posts: 73
Joined: Tue Aug 25, 2015 3:42 pm
Location: Mt Holly, NJ
Contact:

Inserting multiple names into dialogue [SOLVED]

#1 Post by Soliloquy » Wed Apr 06, 2016 5:35 pm

Hello everyone!

I was looking for a bit of help with my code. My current game plan is to have three entwined, yet separate, stories. My character select screen contains three lovely ladies, each with a name and a class. Right now, I'm using an image map, but I might change that to image buttons as I get more familiar with them. I would like to be able to insert the names/classes of these wonderful women into dialogue.

I know that %(name/class)s can be used for a single name, but I don't know if that can be used for more than one. I also don't know how to store the name/class variables in relation to the select screen, or if that code would change once I make the switch from image map to buttons.

Can any Py-expert out there tell me where to begin? :)
Last edited by Soliloquy on Fri Apr 08, 2016 2:05 am, edited 1 time in total.

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Inserting multiple names into dialogue

#2 Post by mobychan » Thu Apr 07, 2016 2:20 am

You can use multiple names the same way as only one name, just give them different variables^^

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Inserting multiple names into dialogue

#3 Post by Onishion » Thu Apr 07, 2016 4:28 am

So if the character's names could be "Larry, Curly, or Moe" and someone is addressing Moe, you want the dialog to say "So how are you doing, Moe?" while if they are addressing Larry, it says "How are you doing, Larry?"

Well the way I'd do it, maybe not the best way, would be something like:

Code: Select all

$ ObjChar = "Moe"
"How are you doing, [ObjChar]?"
Then you could change the ObjChar variable any way you like, either having it set by a menu choice, or by the outcome of an event, or whatever would cause the statement to be directed at that character.

User avatar
Soliloquy
Regular
Posts: 73
Joined: Tue Aug 25, 2015 3:42 pm
Location: Mt Holly, NJ
Contact:

Re: Inserting multiple names into dialogue

#4 Post by Soliloquy » Fri Apr 08, 2016 12:09 am

Onishion wrote: Then you could change the ObjChar variable any way you like, either having it set by a menu choice, or by the outcome of an event, or whatever would cause the statement to be directed at that character.
Which brings me to the second half of my problem: how do I integrate this with my character select screen?

I did define a few characters, as mobychan suggested, and put them in as a test. I got <(the three characters) unbound> in the dialogue. Obviously, either your code or mobychan's would work, but I don't know how to store my variables in conjunction with the character select. Any help on that matter would be greatly appreciated. ^^

User avatar
Soliloquy
Regular
Posts: 73
Joined: Tue Aug 25, 2015 3:42 pm
Location: Mt Holly, NJ
Contact:

Re: Inserting multiple names into dialogue [SOLVED]

#5 Post by Soliloquy » Fri Apr 08, 2016 2:06 am

As usual, trooper6 came to the rescue!

I accidentally posted in the wrong subforum, but got a great answer anyway. I'm going to post it here, for the sake of those who might come after me with a similar problem. :)
trooper6 wrote:Here is code that allows you to set the name and class of someone using a variable and then use those variables in text. Study this code:

Code: Select all

default name1 = Null
default class1 = Null

screen chooser():
    vbox:
        text "Pick one."
        textbutton "Jane" action [SetVariable("name1", "Jane"), SetVariable("class1", "Warrior"), Return("smth")]
        textbutton "Betty" action [SetVariable("name1", "Betty"), SetVariable("class1", "Rogue"), Return("smth")]
        

label start:
    "Choose the woman."
    call screen chooser
    "You have chosen [name1], who is a [class1]."
Note:
Documentation on screen language is here: https://www.renpy.org/doc/html/screens.html
Documentation on screen actions is here: https://www.renpy.org/doc/html/screen_actions.html
Documentation on text interpolation is here: https://www.renpy.org/doc/html/text.html

Post Reply

Who is online

Users browsing this forum: Alex, nyeowmi