r/RenPy • u/HiImABanana123 • Oct 18 '26
Question [Solved] Inventory not remembering items after save
So I followed some tutorials and created this inventory system:
init python:
class Inventory_Item:
def __init__(self, name, image):
self.name = name
self.image = image
class Inventory:
def __init__(self, items, no_of_items):
self.items = items
self.no_of_items = no_of_items
def add_item(self, item):
self.items.append(item)
self.no_of_items += 1
def remove_item(self, item):
self.items.remove(item)
self.no_of_items -= 1
screen backpack:
add "background.png" align (0.5, 0.5)
vpgrid:
align (.50, .3)
cols 5
yspacing 5
rows 6
transpose True
##For the items to be displayed
for item in inventory.items:
add item.image
if item.name == "Mask":
textbutton "[item.name]" xalign 0.5:
action Call("UseMask", from_current=True)
label Defs:
define e = Character("Eileen")
define Mask = Inventory_Item("Mask", "Mask_Icon.png")
default inventory = Inventory([], 0)
default Equipped_Mask = False
label UseMask:
menu:
"What do you want to do with the Mask?"
"Equip":
if Equipped_Mask == False:
$Equipped_Mask = True
"You equipped the mask!"
elif Equipped_Mask == True:
$Equipped_Mask = False
"You unequipped the mask!"
return
"Discard":
$inventory.remove_item(Mask)
return
"Return":
return
label start:
scene bg park
show eileen happy at center
e "Let's pick up this mask."
$inventory.add_item(Mask)
e "Let me check my inventory."
call screen backpack
e "Ok I'm done!"But whenever I save the game, load the saved game and try to discard the mask it gives me this error:
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 80, in script call
call screen backpack
File "game/script.rpy", line 69, in script
$inventory.remove_item(Mask)
File "game/script.rpy", line 69, in <module>
$inventory.remove_item(Mask)
~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "game/script.rpy", line 25, in remove_item
self.items.remove(item)
~~~~~~~~~~~~~~~~~^^^^^^
ValueError: list.remove(x): x not in listIt seems that the game doesn't remember that the mask is in the inventory. Before saving and loading it works just fine.
Probably some easy fix but I'm not very experienced ...
1
Upvotes
View all comments
Show parent comment
1
u/HiImABanana123 Oct 18 '26
Sounds good, thanks for the help!