How to use the Inventory
by Al Staffieri Jr.The inventory system is very easy to use. It's limited to holding 15 items and you can only equip 1 item at a time, but if you simply want your game to be able to use items that are in the players inventory then you don't have to force the player to equip any items at all.
The inventory system consists of the following commands
INVENTORY WINDOW
INVENTORY SELECT item$
bool = INVENTORY item$
INVENTORY ADD item$
INVENTORY DELETE item$
a built in variable named inventory$
To show the list of inventory items the player has:
INVENTORY WINDOW
That will show a window with the list of items. If you have the Inventory button showing at the bottom of the game window, the player can click that to automaticaly show the inventory window ,so you may not even need to use this command anywhere. The inventory window lets the player pick an item to equip. All they have to do is click the mouse on an item in the list and it will automatically be the equipped item.
You can also equip an item in code rather than having the player pick one:
INVENTORY SELECT sword
That will equip the sword if it's in the inventory list.
To check if an item is in the inventory:
bool = INVENTORY item$
So if you are checking to see if the player has a sword:
x = INVENTORY sword
IF x = 1 THEN
' the sword is in the inventory list if x = 1.
If you only want to check if an item is the equipped item then check the built in inventory$ variable. That will hold the current equipped item:
IF inventory$ = "sword" THEN
' if it does then the sword is the equipped item
When the player finds an item and you want to add it to the inventory:
INVENTORY ADD sword
That adds the sword to the inventory window list.
To delete an item from the inventory
INVENTORY DELETE sword
To delete the entire inventory list, just use INVENTORY DELETE without putting any item after it.
This is probably the easiest inventory system in any game creator because you can let GameMaker handle most of it if you have the "Show Inventory" button selected in the main editor window. Then all you have to do is add items, delete items and check that they player has them.