Gw Temp


Tutorial - 'Item Systems' by videogamerx2

An item about Gamemaker posted on


A tutorial on how to make an item system in GameMaker.


*GAMEMAKER Items System Tutorial*

-By VideoGamerX2


This tutorial will instruct you in-depth with examples on how to create an item system for an rpg made in Game Maker.

This tutorial will be written all in GML (Game Maker Language), in a format easy enough for someone who has just started GM to understand.

The items:

This system can have any number of items, but the calue must be set in the beginning of the game. I will be using a system that supports up to 99 items.

Bear in mind as the value is raised/lowered processing time and complexity acts accordingly (though nothing severe).

The method:

This system uses two arrays, an array is a a list of values, and is also known by the term "matrix." It is basically a good way to store large quantities of

numbers in an easilly addressable fashion.

The first array is a 2x99 array. This means it has 99 columns and 2 rows. Each column represents a certain item in its corresponding slot in the player's

inventory. The first row holds the value for item id, and the second row holds the quantity of that item.

The second array is a list of corresponding strings for item ids. Note that this should be a total number greater than the first array, or equal if you want

the player to be able to hold all the items at once. Having a larger number of items than slots results in a limited inventory, which can be desirable or


So if the first array is 2x99, you could make the second array also 2x99. There would be 99 pairs of entries, one for item name and one for item


These would be set at the start of the game. I will work with a smaller itemset for purposes of this example, with a max of 10 items, but your game will

likely have more.

Creation event:


Now we have set up the player's inventory. This sets all item slots to empty, with a value of -1 (which will be interpreted as an empty slot).

Next we must set up the item name list:

itemarray[0,1]="Gives Back 10 HP"
itemarray[1,1]="Gives Back 100 HP"
itemarray[2,1]="Gives Back 1000 HP"
itemarray[3,1]="Fully Restores HP"
itemarray[4,1]="Restores 1 MP"
itemarray[5,1]="Restores 10 MP"
itemarray[6,1]="Fully Restores MP"
itemarray[7,1]="Restores 50% HP and MP"
itemarray[8,1]="Fully Restores MP to Entire Party"
itemarray[9,0]="Strength Medicine"
itemarray[9,1]="Gain Strength +1"

As you can see, this must be adapted on a per-game basis, and for larger games, you may want to do this using a text file and a script. Note that this

method allows for in-game modification of item names, so this could be adapted to many things, for example, a key item that is used once could be renamed to

a new one, or you do stuff like add the name of a player inputted by the user, like "Alex's Personal Sheild"

From this point, we have set up an item database, and now we need to manipulate it, namely we must find a way to add/change items, display them, and sort


Say the player has found a potion item. First thing to do is check if there are any potions already, and if so, add the potions to that, otherwise we must

add them to the first available empty slot.

I would suggest creating a message box script, and displaying a message like "Found" and then itemarray[0,0] using two draw_text() functions to the effect of

"You have found 10 Potions" (You will need to have a variable for itemsfound, the id of the found item and if it is >1, add the "s" to the end of the word to

indicate pluralism)

Next step is to do this:

if itemarray1[i,1]=idfound
if !a{for (i=0,i<=10;,i+=1){if itemarray1[i,1]=-1{itemarray1[i,1]=idfound;itemarray1[i,2]=itemsfound;break}}}

We have now scanned the database and added in the item.

To draw the items:

Do something like this:

if itemarray1[1,0]!=-1{

This will draw all the current items and wait for keyboard input,how to do this depends on the desired aesthetics, I would suggest creating a cursor that

responds to commands and holds the current slot, which displays the corresponding description for that slot in a box at the top of the screen.

To switch the items, you would just switch the values for the two slots requested to be switched.

I hope this helps people out there to understand item systems in GM, and will lead them to create better rpgs on the maker than have been seen in the amateur

Game Making community, as you can probably see since this item system is built from scratch the possibilities are infinite, while in rm2k/3, they are


PM any questions to videogamerx2 on the Gaming World forums.