[SOLVED] Confused about interpolation using !i or !ti

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
goldo
Regular
Posts: 63
Joined: Mon Jan 23, 2017 8:23 am
Contact:

[SOLVED] Confused about interpolation using !i or !ti

#1 Post by goldo » Tue Jan 26, 2021 5:17 pm

Hi guys,

So I'm looking at this part of the documentation: https://www.renpy.org/doc/html/text.htm ... ating-data

But I cannot get this simple code to work:

Code: Select all

label test_interpolation():

        $ text1 = "Hello, [MC.name]."

        girl "[text1!ti]" # text1!i doesn't work either

        return
And then nothing happens (see attachment). Am I misunderstanding how interpolation works?

Of course I could replace the text with something like:

Code: Select all

"Hello, %s." % MC.name
or

Code: Select all

"Hello, " + MC.name + "."
But I would really like to make the first code work, it's just a lot easier to read and write, and the documentation makes it sound like it should work.

Any insight would be welcome. Thanks!
Attachments
Capture.PNG
Last edited by goldo on Fri Feb 05, 2021 8:58 am, edited 1 time in total.

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Confused about interpolation using !i or !ti

#2 Post by _ticlock_ » Tue Jan 26, 2021 11:12 pm

Hi, goldo,

I tried your code, it works fine for me. I guess MC is an instance of some class. Maybe the code of this class will help to understand why it doesn't work.

goldo
Regular
Posts: 63
Joined: Mon Jan 23, 2017 8:23 am
Contact:

Re: Confused about interpolation using !i or !ti

#3 Post by goldo » Thu Jan 28, 2021 6:20 am

Well, MC is a complex class but its 'name' property has nothing special to it, it's just a regular variable that gets assigned a string upon starting the game.

Code: Select all

label start:
	MC_name = "Nero"
        MC = Main()    

init python:
    class Main(object):

        """This class is for the main character."""

        def __init__(self):

            self.name = MC_name
            
            [...]
            
            
The game runs on 7.3.5.606, so unless things changed recently, it should be working.

The only thing I can think of is that the game was created on an earlier version of Ren'py, back when '!i' didn't exist, and I ported it to 7.3.5 but maintained the old UI system (using themes).

The say screen thus looks like this:

Code: Select all

## Say screen ##################################################################
##
## The say screen is used to display dialogue to the player. It takes two
## parameters, who and what, which are the name of the speaking character and
## the text to be displayed, respectively. (The who parameter can be None if no
## name is given.)
##
## This screen must create a text displayable with id "what", as Ren'Py uses
## this to manage text display. It can also create displayables with id "who"
## and id "window" to apply style properties.
##
## https://www.renpy.org/doc/html/screen_special.html#say

screen say(who, what, side_image=False):
    style_prefix "say"

    # The one window variant.
    window yalign 1.0 ysize int(config.screen_height*0.2) xpadding 20 ypadding 10:
        id "window"

        has vbox:
            style "say_vbox"

        if who:
            text who id "who"

        text what id "what"

    # If there's a side image, display it above the text.

    if side_image:
        fixed xsize 150 ysize 150 xalign 0.0 yalign 1.0:
            add side_image xalign 0.5 yalign 0.0
    else:
        add SideImage() xalign 0.0 yalign 1.0

    # Use the quick menu.
    use quick_menu

style window is default

style window:
    xalign 0.5
    xfill True
    yalign gui.textbox_yalign
    ysize gui.textbox_height

    background Image("gui/textbox.png", xalign=0.5, yalign=1.0)
I don't think I really changed anything to it.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Confused about interpolation using !i or !ti

#4 Post by Remix » Thu Jan 28, 2021 3:01 pm

I believe !i is 7.4 and newer.

You should also default your variables. If MC_name does not change after you create it (doing it your way) there is no guarantee that Ren'Py will add it to the store (whereas with default there is a guarantee).
Creating variables in labels is not a good idea in modern Ren'Py. Either define them (not stored, just for values that never change) or default them.
Frameworks & Scriptlets:

goldo
Regular
Posts: 63
Joined: Mon Jan 23, 2017 8:23 am
Contact:

Re: Confused about interpolation using !i or !ti

#5 Post by goldo » Fri Jan 29, 2021 9:27 am

Thank you, this is useful information.

Unfortunately I don't think this relates to my problem: MC.name is a string, and is used everywhere without problems. This works fine, for instance:

Code: Select all

girl "Hello, [MC.name]"
The game was originally created on Renpy 6.18.3 and updated with newer versions since.

goldo
Regular
Posts: 63
Joined: Mon Jan 23, 2017 8:23 am
Contact:

Re: Confused about interpolation using !i or !ti

#6 Post by goldo » Fri Feb 05, 2021 8:58 am

Just to keep you guys updated; I couldn't get the double interpolation to work, but this works as intended:

Code: Select all

label test_interpolation():

        $ text1 = "Hello, [MC.name]."

        $ girl(text1)

        return
Good enough for my purposes. Thank you for your help!

Post Reply

Who is online

Users browsing this forum: Google [Bot]