Dear friends.
The simple adventure game inventory (see https://blenderartists.org/forum/showthread.php?412199-How-to-make-a-simple-adventure-game-inventory&p=3129824&viewfull=1#post3129824) I made so far has the disadvantage that it needs for each kind of “inventory item” an own keyboard key, which limits the amount of them in the game.
I changed this issue using slots accessed by keyboard keys, i.e. each slot has an own key, and the item in each slot is accessed with the key of the slot. So the amount of “inventory items” in the game can be unlimited and only the amount of slots for an inventory is limited by the amount of used keyboard keys for them.
Features / characteristics :
-
Items can be taken from the scene and can be put back to certain places,
-
stackable items in the inventories,
-
The inventories are dictionaries. The dictionary key is the slot number and the dictionary value is a list of two items, which are used for the game item name and the game item amount.
-
The content of the inventories is printed as text to the screen, sorted by the key numbers.
-
Each inventory slot correspond to a keyboard key. The different inventories can use the same keys for their slots, p.e. NUM keys 1 to 5 for the slots 1 to 5.
-
interaction of player inventory with container inventory by keyboard keys in both directions. Each key press substrates one item from one inventory and adds it to the other. The output on screen of the content of the implicated inventories is refreshed and shown after each action.
-
certain object names are shown if the mouse is over them.
Disadvantages :
-
The maximum amount of slots of an individual inventory is limited by the amount of used keyboard keys for the slots. But all inventories can use the same keys for the slots.
-
The code results to be long if we integrate interaction with containers, because then:
-
for each container we need an interaction code which consists of code blocks of ca. forty lines for each slot of both interacting inventories, i.e. the container and the player inventory.
-
for each kind of ‘get- and dropable item’ we need an own code block of fifteen lines per possible position in the player inventory to drop them back to the scene. The others items will not cause this increase.
Credits :
Thanks to all the visitors of my threads, who’s thought and wishes related with them have pushed me so far.
Contents :
How to make inventory slots accessed by keyboard events -> please scroll down a little bitChanging some keys to Python keyboard ‘all keys’ events
How to use Python Keyboard ‘All keys’ events with character motion
How to use Python Keyboard ‘All keys’ events with the AND operator
How to use Python Keyboard ‘All keys’ events with the OR operator
How to add an item to an inventory slot -> 3139634How to drop an item back to scene from an inventory slot
How to make items stackable in inventory slots -> 3139644Changing the structure of the inventory dictionary
Adding stackable items to the inventory
Dropping stackable items to the scene
The container slots -> 3140049The consequences caused by them
How to add a slot to an existing inventory
[INDENT=2]Comparing two interacting inventories
[/INDENT]
How to add a new item to the game
How to interact with Box_01 -> 3140050How to add items from the player inventory to Box_01
How to add items from Box_01 to the player inventory
I will start with the explanations in the next post.
Greetings
achisp