Redefining character attributes via an if statement...

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
Cafechan
Regular
Posts: 107
Joined: Fri Aug 13, 2010 5:09 am
Completed: algormortis
Projects: The Duenkhy, Lights on Stillwater Hill
Contact:

Redefining character attributes via an if statement...

#1 Post by Cafechan »

This is such a specific question, but I want to redefine a character to have an added suffix to all their blocks of dialogue if they're named a certain thing. So as it stands, their code looks like this:

Code: Select all

define m = DynamicCharacter("jun", color="#8FAB67", font = "fontarialrounded.ttf" , show_two_window=True, what_prefix='"', what_suffix='"', ctc="ctc_animation", show_side_image=Image("jun_side.png", xalign=1.0, yalign=1.0), window_right_padding=220)
I don't wanna say what I'm actually doing with this, so for example, let's just say that if the character is named "Cat" they end all their sentences with "MEOW".

By the way, my name input code is this:

Code: Select all

$ jun = renpy.input("Please type your name and hit enter, or just hit enter to go with the default name.", length=11)
So I want to do an "if" statement along the lines of:

Code: Select all

if jun = Cat:
    what_suffix='MEOW'
Obviously that's not the proper code, but hopefully that conveys what I'm trying to accomplish. So, how can I re-redefine a defined character with an if statement? I HOPE THAT MAKES ANY SENSE...

User avatar
Camille
Eileen-Class Veteran
Posts: 1227
Joined: Sat Apr 23, 2011 2:43 pm
Completed: Please see http://trash.moe
Projects: the head well lost
Organization: L3
Tumblr: narihira
Deviantart: crownwaltz
itch: lore
Contact:

Re: Redefining character attributes via an if statement...

#2 Post by Camille »

So you can do this by using a variable to define your suffix.

In an init, do this:

Code: Select all

init:
    $ m_suffix = ""
Then your character code should look like this:

Code: Select all

define m = DynamicCharacter("jun", color="#8FAB67", font = "fontarialrounded.ttf" , show_two_window=True, what_prefix='"', what_suffix='[m_suffix]"', ctc="ctc_animation", show_side_image=Image("jun_side.png", xalign=1.0, yalign=1.0), window_right_padding=220)
Finally, after the player has chosen a name, just put something in like this:

Code: Select all

if jun == "Cat":
    $ m_suffix = " MEOW"
That'll make it so that the character's dialogue will be "Something something MEOW" if the name is cat, but just regular "Something something" if not. If m_suffix isn't redefined, it'll basically show up as nothing if you code it this way, since it's set to be nothing in the init.

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Redefining character attributes via an if statement...

#3 Post by PyTom »

I'm about 80% sure you can do this by including square bracket substitution in the what_suffix.

Code: Select all

define m = DynamicCharacter("jun", color="#8FAB67", font = "fontarialrounded.ttf" , show_two_window=True, what_prefix='"', what_suffix='[m_suffix]"', ctc="ctc_animation", show_side_image=Image("jun_side.png", xalign=1.0, yalign=1.0), window_right_padding=220)

label start:

    menu:
        "Is jun a cat?"
        "Yes":
            $ m_suffix = " MEOW~"
        "No":
            $ m_suffix = ""

    m "Does is sound like I'm a cat?"
If this doesn't work, let me know and I'll see about fixing the problem.

EDIT: Camille's solution is the same save for details.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Cafechan
Regular
Posts: 107
Joined: Fri Aug 13, 2010 5:09 am
Completed: algormortis
Projects: The Duenkhy, Lights on Stillwater Hill
Contact:

Re: Redefining character attributes via an if statement...

#4 Post by Cafechan »

Thank you so much!!! So like, it works if i define the name as Cat, but if I define it as anything else, this happens :<

EDIT: WHOOPS I FIXED IT. Thank you so much, both of you!!!!!

Post Reply

Who is online

Users browsing this forum: No registered users