help with invantory system !
Posted: Sat Dec 04, 2010 6:48 am
Hi, i have a trouble with my version of inventory script !
i have the number of object, but i want in def buy the number of the item i have buy as +1, i use
"items.nbr += 1" but that dosent fuction !
thanks for advance !
i have the number of object, but i want in def buy the number of the item i have buy as +1, i use
"items.nbr += 1" but that dosent fuction !
Code: Select all
init python:
class Item:
def __init__(self, name, cost, nbr):
self.name = name
self.cost = cost
self.nbr = nbr
class Inventory:
def __init__(self, money=10):
self.money = money
self.items = []
def buy(self, item):
if self.money >= item.cost:
self.money -= item.cost
self.items.append(item)
return True
else:
return False
def earn(self, amount):
self.money += amount