Page 1 of 1

call value dimensional dictionary with variables

Posted: Sun Mar 14, 2021 3:56 pm
by smollvrn
hello, how to call dimensional dictionary with variables in say one line ????

Code: Select all

$ my_dict = {
           "key": ("0", "1"),
           "key1": ("0", "1")
           }
$b = key           
$i = 0

# work
a "[my_dict[key][0]]"

$c = my_dict[b][i]
a "[c]"


 #doesn't work
a "[my_dict[b][i]]"





Re: call value dimensional dictionary with variables

Posted: Sun Mar 14, 2021 5:23 pm
by zmook
The documentation for string substitution/interpolation is here: https://www.renpy.org/doc/html/text.htm ... ating-data

If I am reading it right, substitution of dictionaries isn't fully supported, just "simple variables" and "fields and components of tuples". At any rate, the extra layer of square brackets is confusing it. I'd suggest either converting my_dict to a class so you can use field notation (ie, "The magic number is [my_data.key1[0]]"), or if that's impractical, you can force full python substitution like this:

Code: Select all

    $ a( "the number of the counting is %s" % my_dict[b][i] )