So Ive been trying to make a method which checks if an entered Item is present in the players inventory. For that I used the count to check if the item exists atleast once. However it seems like that it does not instances of the class. (All the items in the inventory of the player are instance of a classs)
inventory = []
def equipItem(self):
equipinput = input("Chosse Item to equip: ")
#Get Input which item to equip
itemcount = self.inventory.count(equipinput)
#Count how many times the item was found
if itemcount >= 1:
itemindex = self.inventory.index(equipinput)
if self.inventory[itemindex].typeitem == "weapontype":
#Check the item type(is an attribute of the item/Class)
self.inventory[0], self.inventory[itemindex] = self.inventory[itemindex], self.inventory[0]
#Switch position of the item to equip and that of the current item (It is always on the first position)
print("Changed Weapon to " + str(equipinput))
game()
#Go back to the game
else:
self.inventory[1], self.inventory[itemindex] = self.inventory[itemindex], self.inventory[1]
print("Changed Armor to " + str(equipinput))
game()
else:
print(f"{Fore.RED}You do not have this item!{Style.RESET_ALL}")
#Output an error Message in red
game()
Example inventory:
self.inventory = [Wooden Dagger, Steel Sword]
Example input would be then: Steel Sword
Expected Output/inventory:
self.inventory = [Steel Sword, Wooden Dagger]