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"
Using a List as a dict value in dialogue
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.
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.
Re: Using a List as a dict value in dialogue
It's a limitation of square bracket interpolation - you should use renpy.say to use python .format interpolation.
That said, not sure this is worth the effort given the simplicity of the variables in this specific case.
Code: Select all
$renpy.say(None, "We're going {}!".format(Directions["up"][Invert]) #also do note up should be in quotesRe: Using a List as a dict value in dialogue
Ok, thanks. I'll see how this fits in with the rest.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot]