


We're going to define a number of different macros that will all be used to make it easier to control what's happening with our inventory, starting with some macros for each of the different item types that our game can have - in this case a sword, a bow, a key, a potion, and food, and we also define a macro for when no item is present: // Item Definitions
#MENU COFFEE BREAK CODE#
By default it'll be created with the code to create a function, but we don't need that to define macros as they'll be pre-compiled when you run the game anyway, so delete all the code in the script before continuing. For this we'll create a new script asset and call it init_game. Let's go ahead and create these macros now.

Why is this useful to us? Well, it means that we can essentially assign names to the different slots in an array, which in turn means you don't have to remember which number corresponds to which value in the array, as you simply use the predefined macro. This means that once you assign a value to a macro, it can be used everywhere in your code and you'll know that it will always be the same, no matter what. In GameMaker Studio 2 a macro is a type of constant that is created with a value when the game is first run, and the value it is given never changes and cannot be changed in the game. Don't worry if this seems a little confusing as I'm sure it'll become clearer as we put it into practice! In fact, the next thing we need to discuss is an ideal way to make working with arrays a lot easier, and that's to use macros. We would access the array using the following syntax: amount = inventory_arrayĪrray slots are always counted from 0, so slot 3 in the inventory is slot 2 of the array, and it holds another array where its slot 2 is the amount of items being stored. So, for example, say we want to get the amount of items in the inventory slot 3. Below you can see a schematic image of how this is going to work: This second array which will correspond to the information about the item being stored. What this means is that we'll have our base array - that corresponds to each of the item slots in our inventory - as our first dimension and then each "slot" of that array will itself contain another array as the second dimension. NOTE: For more information on arrays and how they work, please see the manual.įor our inventory, we'll be using a 2 dimensional array. An array is really just a way of making a single variable hold more than one value, and they are incredibly useful when programming as they permit you to easily store large amounts of data using a single "source" variable, and also permit you to easily iterate over that data using a loop.

To manage our inventory we're going to be using arrays. NOTE: The graphics used in the demo project are courtesy of Kenny Assets, and we highly recommend checking out their stuff as it's great for rapid prototyping and getting started making projects in GameMaker! So, let's fix that and create an actual working inventory! If you run the project you can use the mouse-wheel up or down to change the currently selected inventory slot, but not do much else. The inventory has some basic code to track the currently selected "slot" and to draw itself to the screen, while the item object simply selects a sprite to display from a selection of possible item sprites. You'll see we have an inventory object and an item object. If you prefer to use DnD™ to make your games, we have a companion article for you here.īefore getting stuck in, we recommend that you take a moment to look through the project as it already contains some objects and some code to make your life easier. NOTE: This tutorial is for people that use GML.
#MENU COFFEE BREAK DOWNLOAD#
Now, before getting started, this tutorial requires you to download the following the project and open it in GMS2: In this tutorial we'll be looking at using arrays and macros to construct our inventory, and by the end of it you'll have a small project with a five slot inventory that permits you to pick things up, stack them, and then put them down again.
#MENU COFFEE BREAK HOW TO#
Hello and welcome to another one of our coffee-break tutorials! This time around we're going to be showing you how to make a simple inventory system in the style of the original "Zelda" games.
