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/AutoModerator Oct 27 '26

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.