user11000203
user11000203

Reputation: 21

python text rpg inventory system

I'm making a text-based rpg with python 3.3 and I am wanting a more dynamic inventory system for my game. I am currently using variables assigned to each item but with functions, the variables I am passing as arguments are becoming too many and quite cluttered. If there is a better way out there I would love help creating a better system.

Here is how my inventory call system looks right now:

print('Item1',item1)
print('Item2',item2)
print('Item3',item3)

and so on.

Upvotes: 0

Views: 4348

Answers (2)

Volatility
Volatility

Reputation: 32300

You could try and use a list:

inventory = []
inventory.append(some_item)

And you can implement an inventory cap:

if len(inventory) > inventory_size:
    print('Inventory full.')

If you want to 'use' an item in the inventory, say, then it's also easy to remove (this is of course assuming the index exists):

# use the item
del inventory[index]

Obviously most of the functionality you need is accessible through standard list methods, so check the documentation out.

Upvotes: 1

ShroomBandit
ShroomBandit

Reputation: 441

Well, I have an old text game I made and the inventory system I use is just a list named 'inv'. Then all you have to do when you gain an item of whatever type is to append the inventory list with the string.

inv = []

inv.append('Item1')

Then you can create a dictionary with the key as the item name and the value be a list you can reference. Try this:

itemvalues = {'Item1':[0,0,0]
}

And the list can be a bunch of different attributes such as buy sell price, strength or what have you. Hope this helps.

Upvotes: 1

Related Questions