Page 1 of 1

Using a List as a dict value in dialogue

Posted: Wed Oct 26, 2022 7:56 pm
by Onishion
I'm trying to make a dict that uses lists as the values, and then reference that list within a dialogue string. The closest I've gotten allows me to create the dict and access it using a fixed number in the string, but trying to use a variable to select the position in the list breaks it. I have a few less elegant workarounds, but if I could actually get this to work as intended, it would be much cleaner.

$ Directions = {'up':['up','down'],'left':['left','right']}
$ Invert = 0
"We're going [Directions[up][0]]!" #works, says "We're going up!"
"We're going [Directions[up][1]]!" #works, says "We're going down!"
"We're going [Directions[up][Invert]]!" #fails, regardless of what "Invert" is set to, says "list indecies must be integers, not unicode"

Re: Using a List as a dict value in dialogue

Posted: Wed Oct 26, 2022 9:57 pm
by philat
It's a limitation of square bracket interpolation - you should use renpy.say to use python .format interpolation.

Code: Select all

$renpy.say(None, "We're going {}!".format(Directions["up"][Invert]) #also do note up should be in quotes
That said, not sure this is worth the effort given the simplicity of the variables in this specific case.

Re: Using a List as a dict value in dialogue

Posted: Wed Oct 26, 2022 10:26 pm
by Onishion
Ok, thanks. I'll see how this fits in with the rest.