Renpy Inventory System Class Errors
Posted: Wed Jul 04, 2018 12:20 am
So I'm working off of this cookbook instructional viewtopic.php?f=51&t=44730 I'm disregarding things about weight because weight doesnt factor into my game.
which I know is usually because of the wrong number of arguments in a class, my classes look like this
I thought it was because I wrote
and not
but when I add inventory to the class I get
which i dont understand or know how to fix.
Code: Select all
TypeError: __init__() takes exactly 1 argument (2 given)
Code: Select all
init python:
class Item(object):
def __init__(self, name):
self.name = name
class Inv_Item(object):
def __init__(self, item, amount):
self.item = item
self.amount = amount
class Container(object):
def __init__(self):
self.inventory = []
def has_item(self, item, amount=1):
if item in [i.item for i in self.inventory]:
if self.inventory[[i.item for i in self.inventory].index(item)].amount >= amount:
return(self.inventory[[i.item for i in self.inventory].index(item)].amount)
else:
return(False)
def find_item(self, item):
return(self.inventory[[i.item for i in self.inventory].index(item)])
def add_item(self, item, amount=1):
self.inventory.append(InvItem(item, amount))
def remove_item(self, item, amount=1):
if self.has_item(item):
self.finditem(item).amount -= amount
if self.finditem(item).amount <= 0:
self.inventory.pop(self.inventory.index(self.finditem(item)))
Code: Select all
class Container(object):
def __init__(self):
and not
Code: Select all
class Container(object):
def __init__(self, inventory):
but when I add inventory to the class I get
Code: Select all
While running game code:
File "game/script.rpy", line 45, in script
python:
File "game/script.rpy", line 49, in <module>
workbag.add_item("Phone")
File "game/script.rpy", line 35, in add_item
self.inventory.append(InvItem(item, amount))
NameError: global name 'InvItem' is not defined
which i dont understand or know how to fix.