[Solved] How can I get string interpolation to also look in the character store?

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
Anarial
Newbie
Posts: 2
Joined: Tue May 19, 2020 2:39 pm
Contact:

[Solved] How can I get string interpolation to also look in the character store?

#1 Post by Anarial »

I'll prefix this by saying that while I've got 10 years of Java enterprise experience under my belt, I'm completely new to Python and Ren'Py.

I know that the string interpolation feature in Ren'Py looks in the global store for substitutions, and if I use the global store everything works fine. I've been trying to tidy up the code that I have, and noted from the documentation that there is a character store as well - so I refactored my character definitions to put them into the character store instead. Obviously this means they're no longer in the global store, so now a bunch of the substitutions in the text no longer work.

Having the characters defined in the character store 'feels' (to my inexperienced mind at least) to be the cleaner/correct thing to do, so I'd like to keep the definitions there if possible. Is there some way I can coax Ren'Py into also scanning the character store when interpolating strings?

Alternatively, is there some way I can indicate in the text itself which store the variable I'm trying to reference is located?
Last edited by Anarial on Tue May 19, 2020 6:04 pm, edited 1 time in total.

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: How can I get string interpolation to also look in the character store?

#2 Post by Remix »

You could prefix the namespace in the interpolation

Code: Select all

define character.e = Character("Eileen")

label start:
    e "My name is [character.e]"
Frameworks & Scriptlets:

Anarial
Newbie
Posts: 2
Joined: Tue May 19, 2020 2:39 pm
Contact:

Re: How can I get string interpolation to also look in the character store?

#3 Post by Anarial »

Interesting - I had tried that and the interpolation still didn't seem to be working. I'll give it another go after clearing out all the rpyc files just in case it was using an older version of the script!

EDIT:
Looks like that did the trick! Thank you for the help

Post Reply

Who is online

Users browsing this forum: Alex, Bing [Bot]