I know how to make an inventory in python useing tuples. What I want to knoe is how to make an inventory that can handle item stachs (i.e. Potion x3).
I also want to know how to make an inventory handle blocks of data lika a monster and it’s stats so that I can make a monster inventory.
Thank you.
Sjoerd
(Sjoerd)
2
Depends a bit if you want it quick 'n dirty, or very nicely to use it in a larger game.
-
Quick and dirty:
inventory = [[“sword”,1],[“shield”,1],[“potion”, 3]]
Just a list of lists. Don’t use tuples, they cannot be modified
-
A bit nicer, dicts:
inventory = {}
inventory[“potion”] = 3
-
very nicely, classes:
class Inventory(dict):
def __init__(self):
dict.__init__()
class Monster(object):
def __init__(self,inventory):
self.inventory = inventory
i = Inventory()
i["potion"] = 3
m = Monster(i)
Study the Python tutorial to get full benefit from classes.
Thank you. I downloaded the pdf version of the python tutorial.