But now I'm having issues with saving and loading and I can't figure out how to fix it. I've read the documentation about saving/loading and I understand what's saved and what's not, but what my game is saving and what it's not doesn't make any sense to me.
I made this little checklist thing on the crafting screen to show which ingredients the recipe needs and whether or not you have the ingredients. This is the code for that:
Code: Select all
for key in angestuff_recipes.inventory[i].item.ingredients:
hbox:
spacing 5
if angestuff_material.has_item(key):
add "gui/button/checkbox_filled.png"
else:
add "gui/button/checkbox_blank.png"
text angestuff_recipes.inventory[i].item.ingredients[key] size 40
After loading, the checklist stays consistent and shows which ingredients you have. But if you try to make the item, it says that you don't have enough, even though the checklist says that you do. Here's the code for making an item (I know it's janky):
Code: Select all
if angestuff_material.has_item(sugar) and angestuff_material.has_item(milk) and angestuff_material.has_item(flour) and angestuff_material.has_item(chocolate) and angestuff_material.has_item(eggs) and angestuff_material.has_item(butter):
$ angestuff_material.remove_item(sugar)
$ angestuff_material.remove_item(eggs)
$ angestuff_material.remove_item(flour)
$ angestuff_material.remove_item(chocolate)
$ angestuff_material.remove_item(milk)
$ angestuff_material.remove_item(butter)
$ angestuff_present.add_item(cookies)
$ cook_item = cookies
show screen item_made
$ renpy.pause()
hide screen item_made
jump cookbook
else:
"You don't have enough for this."
jump cookbook
Here's my classes/functions:
Code: Select all
import renpy.store as store
class InvItem(store.object):
def __init__(self, item, amount):
self.item = item
self.amount = amount
class Container(store.object):
def __init__(self):
self.inventory = []
def add_item(self, item, amount=1):
if item in [i.item for i in self.inventory]:
self.inventory[[i.item for i in self.inventory].index(item)].amount += amount
else:
self.inventory.append(InvItem(item, amount))
def has_item(self, item, amount=1):
if item in [i.item for i in self.inventory]:
if self.finditem(item).amount >= amount:
return(self.finditem(item).amount)
else:
return(False)
else:
return(False)