From 1c1d24a5f078d8375b89f9c8d25440ef8b9ca0c4 Mon Sep 17 00:00:00 2001 From: Ninjdai1 Date: Wed, 18 Oct 2023 14:06:11 +0200 Subject: [PATCH] Moved inventory clear function and added examples --- index.py | 2 +- src/inventory/inventory.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/index.py b/index.py index 7525db6..d9bbcf0 100644 --- a/index.py +++ b/index.py @@ -35,7 +35,7 @@ def start(self) -> None: print(game.player.inventory, "\n") for item in game.player.inventory: - print(itemk) + print(item) #coins.count = -42 diff --git a/src/inventory/inventory.py b/src/inventory/inventory.py index 3cff075..37099c3 100644 --- a/src/inventory/inventory.py +++ b/src/inventory/inventory.py @@ -17,6 +17,10 @@ def add(self, *items: Item) -> None: item.destroyed.connect(self._on_item_destroyed) self._items.append(item) + def clear(self) -> None: + """Clears the inventory""" + self._items = [] + def _on_item_destroyed(self, item) -> None: """Removes inputted item from the inventory""" self._items.remove(item) @@ -29,7 +33,3 @@ def __next__(self): if not self.iter_data: raise StopIteration return self.iter_data.pop() - - def clear(self) -> None: - """Clears the inventory""" - self._items = []