I have a random generator (custom class I made) that creates random toys. I want the shop to take a dictionary and iterate through a for loop, adding a button for each toy that was generated and automatically adding that toy/item into the shop's inventory. If the player clicks the button, the toy is set to the "current toy" variable, and you jump to a label where the "current toy" is removed from the shop inventory and added to the player's inventory.
However! I'm struggling a bit with the syntax. After studying for loops and how they work with dictionaries, I found there's some differences when referencing the key versus the actual value attached to that key. (The item name vs all the stats stored in the item.) Overall it seems a little more complicated than for loops iterating through a list, but I think I'm managing? However, after doing the research and making the code, I found that I'm getting an error message.
If anyone has some advice on how I can go about this better, I would greatly appreciate it! Here is the relevant code:
Code: Select all
screen toybuy:
layer "overlay2"
$ toy_dict = GenerateMultipleToys(3)
$ x = 0
text ("Which toy do you want to buy?") ypos 150 xpos 940
vbox:
ypos 222 xpos 944
for key in toy_dict.values():
'toy{}'.format(x+1) = Item(name=key.name, type="toy", subtype=key.subtype, price=key.price, quality=key.quality, tags=key.tags, used=False, reviewed=False)
toy_store.add_item(toy)
for item in toy_store.list_items():
textbutton ("%s"%item.name) action [SetVariable("current_toy", item.name), Hide("toybuy"), Jump("buytoy1")]
Code: Select all
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.
File "game/locations.rpy", line 148: expected a keyword argument or child statement.
'toy{}'.format(x+1) = Item(name=key.name, type="toy", subtype=key.subtype, price=key.price, quality=key.quality, tags=key.tags, used=False, reviewed=False)
^
Ren'Py Version: Ren'Py 7.3.2.320
Fri Jul 17 17:15:34 2020