GameMaker Studio 2.3 - Beautiful Inventory Part 1: Coding An Inventory

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
greetings and welcome my name is aaron craig with less learners together and this is going to be the final project that we make in this playlist which you will be able to find and download to dissect your own pace in the description down below so we're going to make a beautiful inventory that has descriptions of items drag and drop functionality items that can and cannot stack and locked size inventory we can click on one to bring up a beautiful description with a flashy animation and then we can click on the item to actually activate a script we will also have sorting capabilities inside of this inventory and then you can exit that and leave the menu all of that is going to be in this entire series this video in particular we're going to cover the creation of the inventory using enums and a ds grid and we're going to start talking about the first script we'll write which is add item to master list if you want to follow along i encourage you to download the start here project which has all of the items none of the code just the items and sprites that we're going to be using to save time so you can just start following me and by the end hopefully you will understand exactly how to make your own inventory as i explain why i choose what i do and how to do it so that you can put this into whatever game project you're working on stick to the end for details on the giveaway of my beginner games course alright let's go ahead and dive right in first thing we're going to do is create another object and we'll create an object and i'm going to right click and if you're in 2.3 then you can add objects to anywhere on the asset browser which is pretty cool it just takes a second longer to actually find what i'm looking for i'm going to call this obj items and what this is going to be is our master item list so this is going to have every single item we can have inside of the game it's also going to have all the properties we can have for items so i'm going to add a create event in here i'm going to go in full screen this so we can go to work so this is going to be our master item object and inside here we talked about what all items already have so we're going to go ahead and create that inside of code so all item properties the way we're going to be doing it is by using an enum and we're going to just call this item if you're not familiar with enums then go ahead and research that but for the most part it's just a way of listing things out with typed numbers so i'm going to type in something here called like name and when i access this later if i were to say item dot name i can do that with this kind of typing instead of having to do it as a string or just put in a number because every enum is just a number so this is zero that's what the first one is and then the next one is going to be 1 and so on and so forth we're going to be using these to add things into arrays and ds grids and so it just makes a lot more sense to use it as an enum that way we don't have to remember every single number of inside of like where the ds grid and which one the name is which one the sprite is and so on so the item's going to have a name sprite amount a type a price the object associated with it and the last one is actually just going to be for how many properties there are so name starts at zero height will be the last number and whenever we're creating things we start at zero but the enums like that when we create a ds grid it kind of starts counting at one so we just max it off at the height here and that way we just always know how many properties we have because if you wanted to add in more properties if you had them you just put them underneath the height and then you'll always have the correct height in your ds grid and arrays which is pretty cool are you ready to start making the game of your dreams then head on over to less learners together dot com to check out my trilogy of courses to take you from beginner to expert game development is hard and frustrating when you're going at it alone and you don't have anyone to turn to join me on the journey and i'll be with you every step of the way to alleviate all of that frustration and by the end you'll be ready to make any game you can set your mind to go ahead and get started now at learnerstogether.com okay we're gonna add another enum here called type so in this inventory we're gonna have three kinds we're gonna have weapon armor and consumable your game will probably have more like quest items or something else i don't know there's an unlimited amount that you can do but we're just gonna stick with the basic three we're gonna be able to sort these and have different messages pop up depending on if it's wearable or if it's consumable so i'll show you how to do all of that as well then we're also going to have consumables that can cure certain ailments so an ailment is a bad thing such as being poisoned or if you're confused or maybe you're drunk maybe being poisoned and drunk are actually the same thing well they are the same thing but for this we'll say that they are different enum sort type this is going to be used when we sort our inventory so we're going to be able to sort it by several different ways name amount type price and then same thing here we're going to have a height variable so when we are sorting we're just going to actually be able to say sort it by whichever one it is plus one so to go from name to amount to type to price we'll check if we've reached the height and if so then we'll go right back to name you can add in specific kinds of sorting if you wanted to be able to sort by name and then they wanted to sort by price or something that would also be very simple i'm just going to make it so you can sort by these and it just cycles through them i'm going to press enter a couple times to put this in the middle and i'm going to paste this in so our ds grid is essentially a 2d array now in 2.3 since they've updated it there are no actual 2d arrays like it's all 1d arrays inside of 1d arrays but a ds grid is still going to be a 2d array and this is how it's going to look so we have the x coordinates which is this one here so 0 is going to be an item so and then we have another item over here and then the y coordinates are going to be the actual properties that we set up in the enum item so for the first item it would be 0 0 would be the name 0 1 would be the sprite and so on and so forth that's how we're going to design the grid now you can easily design it the other way but i'm not going to do that simply because i've set it up this way there's no real reason that i've done this besides i just needed to choose one and this is the way i'm used to imagining 2d arrays so it's what i've done so all of the properties like the functions we use for ds width and height if you change this around just reverse those and you'll be good to go all right now we need to actually make the master item list so i'm going to say global.all items equals ds grid create it's going to start with a width of 0 because the width is how many items we have and we start with 0 and the amount of properties or the height is going to be item.height so there you go that's our all items list and so this is what we're going to put all of the master items in and check it against now i'm going to show you what it looks like when we add an item with a script but we're going to do that in the next video the reason for that is i want this series to be as searchable as possible so this was designing an inventory in code the next video is going to be adding items to a ds grid so you'll be able to find that very easily if you want early access to that then go ahead and hop on my patreon where you'll have access to the projects the videos and to me to ask any questions so we're going to create a function called add item to master list and it looks like game maker 2.3 actually keeps track of functions that you've created in the past even when they're not in there this beginner project doesn't have any scripts it does not have this function but i've used it before and apparently it remembers even if i deleted it which is kind of interesting so it's going to look like this we're going to add in an array of properties like we did so the first one that's why i have this up here to remind myself is going to be the name so it's going to be small knife then it's going to be the sprite which would be spr knife we already have that the amount is going to be 1 the type is going to be type weapon then the price it can be any price you want i'll put it at five and the object is going to be obj knife we close that as an array close it up and then when we call this it will add this to our ds grid of all items and we're going to do some checks inside of this function to make sure that what we're adding is appropriate because if we were to come in here and add in another one right here we have no way of knowing that this is incorrect because we're just passing in an array but when we actually get into this function we're going to make sure that we have the correct amount of properties and that everything else is the way it's supposed to be otherwise we'll reject the item because if we tried to add it then our game would crash that's going to come up in the next video on every game maker tutorial and video i put out from here into the future i'm going to be giving away one copy of my beginner game developer course a great way to go from no programming experience to be able to make your own games to be entered to win just like the video and leave a comment showing me your keyboard works you can leave a comment about anything a week after the video is posted i will send you a message with the coupon if you want you can use it for yourself give it to a friend or apply it towards a more expensive course by just sending me an email and letting me know that's what you'd like to do if you want to see more content from me then subscribe and ring the bell to be notified every time i put out a new video but that's all i've got for you so thank you so much for joining me and as i always say keep making keep learning and i'll talk to you later a huge thank you to all of the awesome people who support me over on patreon their names are on the screen now and every dollar pledged helps me create more awesome content you can support me for as little as one dollar a month and get access to exclusive perks like my discord server your name in the credits early access to my youtube videos and courses and more check it out at patreon.com letslearnthistogether.com or find the link in the description below and become a patron today [Music] [Music] you
Info
Channel: Let's Learn This Together
Views: 5,094
Rating: undefined out of 5
Keywords: GameMaker Studio 2.3, GameMaker Studio 2, GameMaker Studio Tutorial, GameMaker Studio 2 Tutorial, GameMaker Studio 2.3 Tutorial, GMS 2, GMS Tutorial, GMS 2 Tutorial, Let's Learn This Together, GameMaker 2.3, GameMaker Projects, GameMaker Studio 2 Coding Inventory, beautiful inventory, GameMaker Studio 2 Inventory, Game Maker Studio Playlist, Coding Inventory, coding inventory system, core of inventory, base of inventory, game development tutorial in english, Yoyo Games, GMS2
Id: tiyVSg5Ispo
Channel Id: undefined
Length: 11min 27sec (687 seconds)
Published: Mon Aug 31 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.