Ren'Py [SOLVED]Variable in string, another case

GoldenD

Member
Sep 30, 2018
102
70
Hi,

i thought it was definetely ok for me and the strings, parameters.... and no. Another case of mysterious string misunderstood.
Ok, let's go

Some declarations :

Python:
init python:
    class Characters:
        def __init__(self, name, imgSay=""):
            self.name       = name
            self.imgSay     = imgSay

define Hero = Characters("Ethan", "player.jpg")

define dialogSample = (
("[Hero.imgSay]", "Blablablabla."),
("[Hero.imgSay]", "Hello dear [Hero.name] Blablablabla")                    #  <==   MY PROBLEM IS HERE  ON [Hero.name]
)
And of course, the call(s) proc :

Python:
call execScene( dialogSample )


label execScene( listEvent ):

    $ dlg_count = 0
    while dlg_count < len(listEvent):

        call displayScene(*listEvent[dlg_count])

        $ dlg_count += 1

label displayScene(idTalker="", dlgScene=""):

    $ idSpeaker = idTalker
    currentSpeaker "[dlgScene]"             =>  PRINT Hello dear [Hero.name] Blablablabla

I've tried ".join, text(), {} .format...... " methods, nothing good but [Hero.name] is not defined

Like usually, an idea, a dream, a cup of tea ??

And of course, all is ok when i don't use [Hero.name]
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,172
Code:
    currentSpeaker "[dlgScene]"             =>  PRINT Hello dear [Hero.name] Blablablabla
That's why in my response to your previous question I used the $ currentSpeaked( dlgScene ) syntax. It will solve your problem.
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,656
23,750
there is no nested text substitution in Ren'Py.
Python:
$ a = "bla"
$ b = "[a]"
"[b]"
will never work.
 

GoldenD

Member
Sep 30, 2018
102
70
there is no nested text substitution in Ren'Py.
Python:
$ a = "bla"
$ b = "[a]"
"[b]"
will never work.
Hm sorry guy but i can certify you than
Python:
currentSpeaker "[dlgScene]"
works fine when i assign a string variable.
 

GoldenD

Member
Sep 30, 2018
102
70
That's why in my response to your previous question I used the $ currentSpeaked( dlgScene ) syntax. It will solve your problem.
Sorry AON, but this give the same result. I'll make more tests with your syntax and control again, but it seems more complicate.
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,656
23,750
problem is, the value of the variable dlgScene is "Hello dear [Hero.name] Blablablabla" and exactly this is what you get as output.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,172
Hm sorry guy but i can certify you than
Python:
currentSpeaker "[dlgScene]"
works fine when i assign a string variable.
This is not what he said.


Sorry AON, but this give the same result.
No, it don't.

You can not perform text interpolation into text interpolation, point. That's what the66 said, nothing more. And like my syntax do not depend of a text interpolation, unlike yours that don't works, it solve your problem.
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,656
23,750
as a side note, why do you make it that complicated and on top try to use an image as sayer?
if you want to process a list of dialogue lines, try this:
Python:
define Hero = Character("Ethan", image="player.jpg")
define dialogSample = [
    (Hero, "Blablablabla."),
    (Hero, "Hello dear [Hero.name] Blablablabla")
    ]

init python:
    def dialogue(list):
        if not list:
            return
        for s, t in list:
            renpy.say(s, t)

label start:
    .
    .
    .
    $ dialogue(dialogSample)
    .
    .
    .
and if you need to add more features for the ADVCharacter class, add them:
Python:
init python:
    class MyCharacter(ADVCharacter):
        def __init__(self, *args, **kwargs):
            super(MyCharacter, self).__init__(*args, **kwargs)
            self.something = kwargs.get("something", None)
 
Last edited:

GoldenD

Member
Sep 30, 2018
102
70
Ok AON and the66,
i think the tone of my answers last night was a bit awkward and i'm sorry for this. I was just in a hurry, and i should not answer yesterday.
I understand what you 2 say about text interpolation and I have trouble with this logic. I'll re-read your answers, rewrite my code for a more "Renpy" conventional logic and maybe it'll become clearer for me.

So, i noticed my say syntax
Python:
currentSpeaker "[dlgScene]"
isn't correct and it's changed, but I don't understand why the variable isn't translate when i make the list
Python:
define dialogSample = (
("[Hero.imgSay]", "Blablablabla."),
("[Hero.imgSay]", "Hello dear [Hero.name] Blablablabla")                    #  <==   MY PROBLEM IS HERE  ON [Hero.name]
)
When i define my list, i just want a simple string with a string variable like a simple
"Hello " + [NameOfYourHero] + ", how are you"
and not a hard coding
"Hello John, how are you !"
.
I thought it'll be easy to do this.

In all case, thanks for your answers and i'll find a solution of course.
(y):coffee:
 

GoldenD

Member
Sep 30, 2018
102
70
as a side note, why do you make it that complicated and on top try to use an image as sayer?
if you want to process a list of dialogue lines, try this:
Python:
define Hero = Character("Ethan", image="player.jpg")
define dialogSample = [
    (Hero, "Blablablabla."),
    (Hero, "Hello dear [Hero.name] Blablablabla")
    ]

init python:
    def dialogue(list):
        if not list:
            return
        for s, t in list:
            renpy.say(s, t)

label start:
    .
    .
    .
    $ dialogue(dialogSample)
    .
    .
    .
and if you need to add more features for the ADVCharacter class, add them:
Python:
init python:
    class MyCharacter(ADVCharacter):
        def __init__(self, *args, **kwargs):
            super(MyCharacter, self).__init__(*args, **kwargs)
            self.something = kwargs.get("something", None)
I’m starting to look at this solution, it seems to be a good track.
In all case, i continue to learn, great thanks for that.
(y)
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,656
23,750
text substitutions are part of the code behind some Ren'Py statements but are not performed while defining an array of tuples.
Python:
define sayer = Character("Sayer")

$ a = "substring"
$ b = "string with a [a]"

$ sayer(b) # OK, text substitution of b
$ renpy.say(sayer, b) # OK, text substitution of b
$ sayer("[b]") # NO, only 1 textsubstitution is performed, b -> "string with a [a]"
$ renpy.say(sayer, "[b]") # NO, only 1 textsubstitution is performed, b -> "string with a [a]"
 

GoldenD

Member
Sep 30, 2018
102
70
I'll follow the66 ' idea with the ADVCharacter class.

But for info, and I know there is a chance that AON corrects me, I found a way with my own code to succeed. I just have to change
Python:
define dialogSample = (
("[Hero.imgSay]", "Blablablabla."),
("[Hero.imgSay]", "Hello dear [Hero.name] Blablablabla")                    #  <==   MY PROBLEM IS HERE  ON [Hero.name]
)
by
Python:
default dialogSample = (
("[Hero.imgSay]", "Blablablabla."),
("[Hero.imgSay]", "Hello dear %s Blablablabla" % (Hero.name))           #  <==  NO MORE PROBLEM
)
In fact, after thinking, Renpy didn't like I use a variable for a constant define. Using Default changes all.

We meet again for my next worries.

Thanks Again.
 
Last edited: