Help with replacing an attribute with a variable?
Posted: Wed Apr 14, 2021 4:25 am
I'm not sure if the question makes sense but basically this is the code I'm working on.
I'm trying to get it so that after picking a random burger (in this case the "beefburger") from a list, it then has it list out the fillings of the beefburger ("beefpatty"). I want it so that whatever burger it randomly picks out, it'll be able to fill in the gaps of Burger.[random burger choice].fillings
I hope that makes sense.
I'm trying to get it so that after picking a random burger (in this case the "beefburger") from a list, it then has it list out the fillings of the beefburger ("beefpatty"). I want it so that whatever burger it randomly picks out, it'll be able to fill in the gaps of Burger.[random burger choice].fillings
I hope that makes sense.
Code: Select all
init -20 python:
class Burger(object):
def __init__(self, id, name, fillings = [], *args, **kwargs):
self.id = id
self.name = name
self.fillings = fillings
init -19 python:
class Burger:
beefburger = Burger(
"beefburger",
"Beef Burger",
fillings = [
"beefpatty"]
)
default possible_burgers = ["beefburger"]
label lbl_pick_burger:
## Pick randomly from list of possible burgers
$ pick_burger = renpy.random.choice(possible_burgers)
"Pick Burger: [pick_burger]."
# $ pick_burger_2 = Burger.pick_burger.fillings ## Doesn't work
# $ pick_burger_fillings = Burger.[pick_burger].fillings ## Doesn't work
"Burger fillings: [pick_burger_2]" ## Attempt 1 Doesn't work
"Burger fillings: [pick_burger_fillings]." ## Attempt 2 Doesn't work
"Burger fillings: [Burger.[pick_burger].fillings]." ## Attempt 3 Doesn't work
return