Aug-30-2018, 12:53 PM
(This post was last modified: Aug-30-2018, 12:53 PM by ichabod801.)
It's kind of hard to answer, because it is unclear what inventory is. If I was to make an inventory, I would use a dictionary:
Of course, this may not work for your inventory. Again, I can't answer the question fully without knowing how inventory is set up.
inventory = {'cutlass': {'cost': 50, 'min_st': 10, 'damage': (2, -2)}, {'battle axe': {'cost': 130, 'min_st': 15, 'damage': (3, 0)}, {'halberd': {'cost': 70, 'min_st': 13, 'damage': (2, 0)}} buy = input('Would you like to buy a weapon? ') if buy.lower() in ('yes', 'y'): item = input('What would you like to buy? ') if item.lower() in inventory: wallet -= inventory[item]['cost'] stuff.append(item) else: print('I don't have that for sale.')Of course, you'd want to put that in a loop so they could buy multiple items. Note
if item.lower() in inventory:
. That is True if the text entered by the user (lower cased) matches one of the keys of inventory. So in my limited example above, it would only be True for cutlass, halberd, or battle axe, ignoring capitalization. Then it would put that key into the player's equipment (stuff), and you could later get the necessary stats like min_st and damage using the key.Of course, this may not work for your inventory. Again, I can't answer the question fully without knowing how inventory is set up.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures