Ren'Py [SOLVED]Call a List by variable Name

GoldenD

Member
Sep 30, 2018
102
70
Hi guys,
do you think it's possible to call a list with a variable name. Sample :

Python:
# .../...

$ myFunction( listOfDialog_Scene001 )
$ myFunction( listOfDialog_Scene002 )
# ...
# Of course I would like something like
$ myFunction( listOfDialog_[variable] )
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,978
16,234
do you think it's possible to call a list with a variable name. Sample :
Not directly with Ren'py, because it lack of a for loop statement (there's just a for screen statement). But you can do it with a python block :

Python:
label whatever:
    python:
        for idx in range( 1, 5 ):
             myFunction( getattr( store, "listOfDialog_{:03d}".format( idx ) ) )
You build the name of the variable with the "listOfDialog_{:03d}".format( idx ) part, that will format the number with 3 digits, filling the empty space with "0".
Then you ask Python to give you the attribute having this name in the "store" object, which will be the value past as argument to the function.
 

GoldenD

Member
Sep 30, 2018
102
70
Not directly with Ren'py, because it lack of a for loop statement (there's just a for screen statement). But you can do it with a python block :

Python:
label whatever:
    python:
        for idx in range( 1, 5 ):
             myFunction( getattr( store, "listOfDialog_{:03d}".format( idx ) ) )
You build the name of the variable with the "listOfDialog_{:03d}".format( idx ) part, that will format the number with 3 digits, filling the empty space with "0".
Then you ask Python to give you the attribute having this name in the "store" object, which will be the value past as argument to the function.
Thanks, Thanks, Thanks (y)