mercredi 26 juin 2019

python class self. name str is not equal to a string with the same value

I try to make a prototype of an inventory and item system with classes. in the "item" class it has a self.name and when I try to see if a string is equal to the self.name in the inventory class it is not equal to each other

I have printed out the info and it says that it is the same and I have tried to do str(variable but that does not work either)


class item:
    def __init__(self, name):
        #name variable
        self.name = name


class itemStack:
    def __init__(self, items=[]):
        self.items = items

    def useItem(self, _item):
        isTrue = False

        for i in self.items:

            #Here is were it is not working//
            if str(_item) == str(i.name):
                #Here is were it is not working//

#creata an item with name of stick
stick = item("stick")
#create a list of items
inventoryItems = [stick]
#create a itemstack with inventoryItems in it
inventory = itemStack(inventoryItems)

inventory.useItem("stick")


it is not an error it just says that it is not equal

Aucun commentaire:

Enregistrer un commentaire