Page 1 of 1

TypeError: 'tuple' object is not callable - inventory issue

Posted: Wed Oct 07, 2020 4:06 am
by goldenphoenyyx

I'm trying to code an inventory:

Code: Select all

image banana:
    size 50,50
default banana_item = Consumable("banana", 10, 10)

init python:
    class Player:
        def __init__(self, hunger, athletic, haggling, gaming, tolerance, charisma, logic, mmusic, cooking):
            self.hunger = hunger
            self.max_hunger = hunger
	def addHunger(self, amount):
            self.hunger += amount
            if self.hunger > self.max_hunger:
                self.hunger = self.max_hunger

    class InventoryItem:
        def __init__(self, img, value):
            self.img = img
            self.value = value

    class Consumable(InventoryItem):
        def __init__(self, img, value, hunger_gain):
            InventoryItem.__init__(self, img, value)
            self.hunger_gain = hunger_gain
        def consumeEdible(self, target):
            selected_item = None
            global selected_item
    $ inventory.append(banana_item)

When I play through it, the game opens fine, but when I open the inventory I get the error: TypeError: 'tuple' object is not callable
Does anyone have any advice on how to fix this? Am I coding the items wrong??

Re: TypeError: 'tuple' object is not callable - inventory issue

Posted: Wed Oct 07, 2020 8:30 am
by RicharDann
It seems you tried to call a tuple as if it was a function, but I don't see anything in the code you posted that could be a tuple.
I don't see your definition of theinventory variable, but if you defined it like a tuple, maybe with default inventory = (), then it should be a list, default inventory = []. Tuples aren't changeable so they don't have an append method.
Also, in the consumeEdible method, you should put the global selected_item statement before changing the variable value, else it won't be changed correctly.