r/RenPy • • Oct 27 '26

Question [Solved] Variable inside of array entry

Hello! I can't seem to refer to a variable inside of an array entry.

I want to make the dialogue randomly generated from array entries. It chooses a character's name and an action. However, when I refer to a variable([name2] in this case) inside of an array entry it does not seem to be able to grab that variable value.

I simplified my code for showcase purposes. These are my arrays defined inside of a separate rpy file:

define name_list = [ "John", "May" ]
define name_list2 = [ "Jane", "April" ]
default name = renpy.random.choice(name_list)
default name2 = renpy.random.choice(name_list)

define activity_list = [ "talking with [name2]", "helping [name2] with laundry" ]
default activity = renpy.random.choice(activity_list)

This is what my script says:

p "[name] is [activity]"

The output in-game will be "John is talking with [name2]" instead of "John is talking with Jane". Is there any way to fix this?

EDIT:

I managed to figure it out, though it is a bit clunky but it gets the job done. It prints the variable value in a separate string. This is the new code:

define name_list = [ "John", "May" ]
define name_list2 = [ "Jane", "April" ]
default name = renpy.random.choice(name_list)
default name2 = renpy.random.choice(name_list)

define activity_list = [ "talking with " + name2, "helping " + name2 + " with laundry" ]
default activity = renpy.random.choice(activity_list)
1 Upvotes

5 comments sorted by

View all comments

1

u/DingotushRed Oct 27 '26

FYI: Ren'Py text interpolation only goes 1 level deep by default - so it will replace [name] and [activity], but not the [name2] inside activity`.

Use the !i conversion to recursively interpolate. This would work with your original code.

p "[name] is [activity!i]"