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

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
goldenphoenyyx
Newbie
Posts: 12
Joined: Thu Jun 20, 2019 6:47 pm
Contact:

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

#1 Post by goldenphoenyyx » Wed Oct 07, 2020 4:06 am

Hello!

I'm trying to code an inventory:

Code: Select all


image banana:
    "gui/banana_idle.png"
    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):
            inventory.remove(self)
            selected_item = None
            global selected_item
            target.addHUN(self.hunger_gain)
            
            
start:
    $ 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??

User avatar
RicharDann
Veteran
Posts: 239
Joined: Thu Aug 31, 2017 11:47 am
Contact:

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

#2 Post by RicharDann » Wed Oct 07, 2020 8:30 am

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.
The most important words a man can say are, “I will do better.”

Post Reply

Who is online

Users browsing this forum: No registered users