reload a gun, cook food, open a letter, open a box, split stacked items, carefully inspect an item, repair a broken item, take out the batteries (for use in another device)… Lots of things you could do, but it might be best to have some general actions. Inspect, open, disassemble, assemble, repair, etc…
Then you can set a dictionary to contain information about each item and a code word for what to do to the item if an action is performed.
A kind of example of this would be:
small_box = {"weight":3,
"weapon": False,
"can_wear": False,
"on_open": "remove_contents",
"contents": None,
"on_repair": None,
"on_inspect": "You don't notice anything unusual.",
def open_item(object):
if object['on_open']:
if object['on_open'] == "remove_contents":
if object['contents']:
put_in_inventory(object['contents'])
object['contents'] = None
else:
print_info_to_console("It's empty!")
else:
print_info_to_console("That can't be opened.")
open_item(small_box)
But if you’re going to get in to that kind of territory you have to start thinking about persistent items, so that you have item templates and instances of those items. You can use classes for this, or just dictionaries or even lists, if you don’t mind remembering which index is which.
Some pseudo code for that might be like this:
import copy
if "ini" not in own:
own['key_id'] = 1
all_items = {}
own['ini'] = True
item_type = "small_box"
item = item_templates[item_type]
new_item = copy.deepcopy(item)
item_dictionary_key = type + str(own['key_id'])
own['key_id'] += 1
all_items[item_dictionary_key] = new_item
If you want to work with an item then, you use its item_dictionary_key to pick it up from the all_items dictionary. You only create a new item when it is placed in to the game, for example when it is first stored in a container, or when a bad guy drops it. it’s really best to store all the instances somewhere central like in global dict or as a property on an easily accessible game object (like the player or main camera for example).
With this method you can keep track of item damage, upgrades or ammo individually. But it does require more design work to get it working well and to be honest it’s not always worth the extra investment unless item management is one of the key pillars of gameplay in your game.