Ren'Py How to change tha way you can call a character by unsing a variable "relationship"

Alt-0069

Member
Aug 27, 2017
108
151
Hello,
I'm new at Renpy and I can't find the answer I'm searching.
I want to change the way the player call a character by using a variable to change the relationship between them but my tries won't work.

I try with a character named Joe Thetest:

default Joe_call = 'Mr. Thetest'
#File 1
label Joe_relationship:
if Joe_R >= 10:
$ Joe_call = 'Joe'
else:
$Joe_call = "Mr.Thetest"
#File 2
label tchat:
#Player do some quests that raise Joe_relationship to 10 and other
$ Joe_relationship +=10

I dont want to change the name by just using $ Joe_call = "...." because I want to make quests with some reward and this try can help me to understant how to do it.
Thank for helping
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
It looks to me that you've already solved your problem, in so much as at least what you have is correct.
(Well, except you're using both Joe_R and Joe_relationship for the same thing - so that could be your initial problem).

This would be more or less what I'd have:

Python:
define j = Character("[j_call]", color="#04B486")

default j_call = "Mr. Thetest"
default j_rel = 0

label start:

    scene black with fade
    j "Hi, I'm [j]."


label game_loop:

    if j_rel >= 30:
        $ j_call = "Joe"
    else:
        $ j_call = "Mr. Testest"

    j "Relationship points = [j_rel]: You should call me [j]."

    menu:
        "Add relationship points":
            $ j_rel += 10

        "Subtract relationship points":
            $ j_rel -= 10

        "Exit":
            jump end_of_game

    jump game_loop


label end_of_game:

    "*** THE END ***"
    return
The key points:
  • The check for if j_rel >= 30: is done in a common place guaranteed to executed after the relationship variable has been updated, but before the name is used again. You could code it over and over again, but if there's a single place (or only a few places) in your code to use it - that would be a lot less spaghetti code.
  • The name of the character is indirect and uses the Character() definition, which in turn uses the j_call variable.
  • Variable values can be displayed within strings by wrapping them in square brackets [ ].
Other than that, what I've written is almost identical to what you already had.

Slightly more complicated versions:

You don't have permission to view the spoiler content. Log in or register now.

Finally...

You don't have permission to view the spoiler content. Log in or register now.
 
Last edited:

Alt-0069

Member
Aug 27, 2017
108
151
Okay... I will try it.
I forgot the "return" ^^
I was thinking I can find a thing to avoid to call label each time.
Thank U
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
I forgot the "return" ^^

The return is not essential - so I doubt it is what was causing you issues. I just tend to write examples where possible that can be copy/paste into an editor and run.

I was thinking I can find a thing to avoid to call label each time.

The closest example to that would be my final version using say_menu_text_filter.
It's a bit of a kludge, but it will do what you're hoping.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
Over kill when it's for a single character, but a generic class can perfectly do it, and do it in real time.

Python:
init python:
    class NameByRelation( renpy.python.RevertableObject ):
        # Will be treated as a attribute in place of a method.
        @property
        def joe( self ):
            # Return the name according to the actual relation.
            return "Joe" if j_rel >= 30 else "Mr. Testest"

    # No need to save it.
    nbr = NameByRelation()


label whatever:
    "Hello [nbr.joe].
 
  • Like
Reactions: kotte