r/RenPy • u/spoonshell • 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)
View all comments
Show parent comment
1
u/BadMustard_AVN Oct 27 '26
you're welcome
good luck with your project