Page 1 of 1

Redefining character attributes via an if statement...

Posted: Tue Oct 06, 2015 1:17 am
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...

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

Posted: Tue Oct 06, 2015 1:33 am
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.

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

Posted: Tue Oct 06, 2015 1:37 am
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.

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

Posted: Tue Oct 06, 2015 4:13 am
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!!!!!