Really nice tutorial guys! There are some interessting concepts in the video. My only feedback: When teaching about drawing the GUI, maybe take a few seconds to show the inbetween results? Now It is a lot of code, followed by a "sudden" appearance of a ui. But that is just my inner tutor speaking ;-) Looking forward to the GM future!
Thank you for the tutorial! It was very informative. A little feedback. The inventory script you created in the video was already complete in the Starter template provided. It also had a recipe script which wasn't used and the font was already made. Wasn't a big deal I just followed along but made me wonder if I had the correct files. Also if you could take a brief pause inbetween typing the code and switching to the running project. It could be difficult to pause at the right time to double check I followed along and typed everything correctly! Thanks!
Timestamp reference: 2:20 Make a constructor function, put an array in that constructor. 2:27 item_set() function 2:49 item_find() function 3:18 item_add() function 4:09 toString() function for displaying inventory contents 4:54 Create Event of obj_Inventory (Wow, this is the first time I understand how constructors are used) 6:00 Briefing on removing items from an inventory 6:40 item_has() function 7:13 item_subtract() function 8:02 item_remove() function 8:48 The UI - a lot of important math 10:04 The real coding 16:48 Combining the system with the UI 17:26 A new function called item_get() [I wonder why it isn't inventoryget()...?] 20:28 Highlight effect
In the starter template version of this. Would it be possible to change it so that you can also choose to use a variable in place of the _requirement instead of an item already in the inventory (account is working properly now)
5:00 I am confused on why we need to create a new variable to represent our inventory script. As when we call other scripts like draw_set, we can just call them. Is it because Inventory as a script contains many other individual functions?
Well you should understand the concept of classes for that to make sense. If you have a dog class you can then make new variables which can contain different dogs, with different colors and names and methods which you give them after calling the constructor. If you need to make multiple dogs then you should make them from a class type of structure. If you only need one, there's no point however, so it's up to you to decide what you need and how to get it.
@@flaminshotgun The script takes input (whatever arguments you pass) and returns output. When you call "new Inventory(args)" you're telling it to create an object. So the assignment is the output of the script (in this case the inventory object created from the Inventory constructor). If you don't do the assignment you could perform one "action" on the object before you lost the reference. (new Inventory(args)).item_add(args) If you tried calling the same line again, then you would end up with two inventory objects and no way to reference either once. Without getting too technical, you can think of your program as street with places to build a house. Each place has an address. When you call the constructor it picks an address, builds the house, and tells you the address. The variable assignment is equivalent to writing the address down. If you want to paint the house later, then you need to know the address. Does that help?
8:15 I am confused why, on line 57 and 58 of the code, when programming the item_remove function, that you input _index to the function. You hadn't declared _index anywhere else in the code up to that point. And we had been using just index until then. I am assuming that I am missing something, but wouldn't the function not work properly and not delete the correct item from the inventory unless we input "index" instead of "_index"?
No, you havent missed anything. the "_index" will be replaced by what ever he saves under _index in the if state. So he creates the _index soley for this if state.
@@thelegendarymushroom80 It just seemed odd that he just used "index" or just "i" so when "_index" came out I didn't know if it were for any specific reason.
I actually figured it out. Not sure if the most efficient way (I only needed it to move left and right) but it worked for me, I'll post the code if someone replies needing it.
@@Spoungebobsquarepan so here's what I did, in the create event I made a ui_index = 0 variable and a last_selected = 0 variable and also a mouse_on = false. Then on the step I did: var right = keyboard_check_pressed(ord("D")) ; var left = keyboard_check_pressed(ord("A")) ; above the var mx and my, then did: if mouse_on = false{ var key_move = right - left ui_index += key_move if (ui_index < 0) ui_index = inventory_columns -1 if (ui_index > inventory_columns -1) ui_index = 0 if (ui_index != last_selected) audio_play_sound(snd_GemPickup,5,0) // this is just the sound effect
last_selected = ui_index } then on the draw GUI I did added a mouse_on = true beneath the part of the code that goes like this if(is_between(mx, pos_x, pos_x + ui_inventory_box)){ if(is_between(my,pos_y,pos_y + ui_inventory_box)) { mouse_on = true // this will activate the mouse and stop you from doing both keyboard and mouse selection, not the best but works for now and then above that I duplicated the hover code and did if ui_index = if ui_index = inventory_index and mouse_on = false as the condition instead of the stuff above. This will highlight the selection based on a or d input. At last I added the same code we use in the step event of the hover to a Key Press event and switched out the inventory_index var for the ui_index variable with a condition above everything of mouse_on = false.
I'm having trouble figuring out how to make the items possible to pick up and move anywhere in the inventory. I had a previous system where that was possible and I switched to this one for the recipe tutorial but can't figure it out.
Well you need to move the item sprite to the cursor's position on every frame, and have a get/set for the grid position on the item so you can set it on click. And the square you set it to is whichever one the cursor is inside of. You can do a binary search for the X coordinates and then one for the Y to figure out what square you're in.
When I was following along, I had a problem with that too. I just set the variables in the create event. Ex: color_border = c_white. Obviously, you can change c_white to something else. But that's just a small fix I found.
I am also very new took me a few minutes to figure it out but if you still need an answer. The color_border is a variable and you are getting the error code because it has not been defined yet. Go into your create tab of obj_inventory and add "color_border = (c_black); You will also need one for color_background. The color can be whatever you wanted it to be i used black as an example. Best of luck.
excuse me but i don't think the "is_between" exist... and i'm confused by it. but then i realized it was from a script you made and it wasn't mentioned in your video.
@@user-yr2gm5ni4c you can download the project from the description and it's a extremely tiny script! that was this: function is_between(_value, _min, _max){ return _value >= _min && _value
Try find a way to store the Inventory [ ] array as a json file on the hard drive when they click save, and then load that same json into the inventory when they load again.
Hi Richard, this night i'd found how to save. And works correctly. Soon i will post a link to joystick method to scrolling inventory and save struct. Matharoo give me the solution
So hard to follow along. The fact that you would skip typing some of the script was even harder because i had to go back in forth instead of following along as you do it Also the script doesn't work
Hard to follow, 1/3 of the variables aren't shown how they are defined. And if you're tweaking it to fit your own thing without his insane parametres too then forget about it. If you don't already know all this, just don't bother ig lol It's a shame GameMaker won't hire people who can actually explain their code, not just write it out and narrate it. No "why" question can be answered by this video lol You can practically mute it and get the same info. Atp just stick to the docs
GameMaker has structs and ds_maps, which both can act like dictionary, if I understand what you mean. In the video structs are being used already for other stuff, but you could actually use it as for inventory itself. Usually one uses dot syntax for accessing, but you can use strings too. So these are basically equivalent: (inventory.wood) and (inventory[$ "wood"]). So finding item becomes trivial, you don't need linear lookup but struct acts like hash map.
👾 More int & adv level tutorials: ruclips.net/p/PLhIbBGhnxj5LaEib5NZT4OEy9vK97dVHt
the function is between:
function is_between(_value, _min, _max){
return _value >= _min && _value
Isso foi muito útil, obrigado 😁
appreciate it
Really nice tutorial guys!
There are some interessting concepts in the video.
My only feedback:
When teaching about drawing the GUI, maybe take a few seconds to show the inbetween results?
Now It is a lot of code, followed by a "sudden" appearance of a ui.
But that is just my inner tutor speaking ;-)
Looking forward to the GM future!
This video is extremely underrated, how did it only get 300 likes? You guys deserve more 😭
cuz not many bother most give up gamemaking
Thank you for the tutorial! It was very informative.
A little feedback. The inventory script you created in the video was already complete in the Starter template provided. It also had a recipe script which wasn't used and the font was already made. Wasn't a big deal I just followed along but made me wonder if I had the correct files. Also if you could take a brief pause inbetween typing the code and switching to the running project. It could be difficult to pause at the right time to double check I followed along and typed everything correctly!
Thanks!
Thanks Ben 😊
As a fresh student, not easy to follow along or adapt this. But it does cover the essentials nicely and im not totally lost just a lot of rewinding
Timestamp reference:
2:20 Make a constructor function, put an array in that constructor.
2:27 item_set() function
2:49 item_find() function
3:18 item_add() function
4:09 toString() function for displaying inventory contents
4:54 Create Event of obj_Inventory (Wow, this is the first time I understand how constructors are used)
6:00 Briefing on removing items from an inventory
6:40 item_has() function
7:13 item_subtract() function
8:02 item_remove() function
8:48 The UI - a lot of important math
10:04 The real coding
16:48 Combining the system with the UI
17:26 A new function called item_get() [I wonder why it isn't inventoryget()...?]
20:28 Highlight effect
omg so excited to try this tutorial tonight!
What is your code text font? It looks really nice.
How would I make it only pop up if I press "I"? Also why does it only get rid of items instead of moving them? Great tutorial btw :)
I get to 6:14 and get a bunch of errors when running. Following step by step...
In the starter template version of this. Would it be possible to change it so that you can also choose to use a variable in place of the _requirement instead of an item already in the inventory (account is working properly now)
what do i have to do if i don't want the player to have more items than the number of slots??
Can open but can't run your file. Getting compile error. What version of Gamemaker you using? BTW its a good tutorial.
what happened to these videos... I wish you bring more such useful tutorials. #gamemaker
How would I go about adding a row of slots at the bottom of the screen that can hold equipped items?
Idk
@@diegocamacho6060 then don't respond dude. Your comment doesn't help at all.
@@SynphulHero yw
Idk
Probably just make a new variable called toolbar which makes a new Inventory() and give it a different UI and grid layout
5:00 I am confused on why we need to create a new variable to represent our inventory script. As when we call other scripts like draw_set, we can just call them. Is it because Inventory as a script contains many other individual functions?
I assume you wouldn't need to if you only need one global inventory. Otherwise we use the local variables to target specific inventory collections.
@@honeybadger9078 I tried it without creating variable and the whole system didn't work. It only works if you make the variable. And I don't know why.
Well you should understand the concept of classes for that to make sense. If you have a dog class you can then make new variables which can contain different dogs, with different colors and names and methods which you give them after calling the constructor. If you need to make multiple dogs then you should make them from a class type of structure. If you only need one, there's no point however, so it's up to you to decide what you need and how to get it.
@@BusinessWolf1 But since we need to provide the arguments for the script, then why does the script need to be assigned to a variable?
@@flaminshotgun The script takes input (whatever arguments you pass) and returns output. When you call
"new Inventory(args)"
you're telling it to create an object. So the assignment is the output of the script (in this case the inventory object created from the Inventory constructor). If you don't do the assignment you could perform one "action" on the object before you lost the reference.
(new Inventory(args)).item_add(args)
If you tried calling the same line again, then you would end up with two inventory objects and no way to reference either once.
Without getting too technical, you can think of your program as street with places to build a house. Each place has an address. When you call the constructor it picks an address, builds the house, and tells you the address. The variable assignment is equivalent to writing the address down. If you want to paint the house later, then you need to know the address.
Does that help?
8:15 I am confused why, on line 57 and 58 of the code, when programming the item_remove function, that you input _index to the function. You hadn't declared _index anywhere else in the code up to that point. And we had been using just index until then. I am assuming that I am missing something, but wouldn't the function not work properly and not delete the correct item from the inventory unless we input "index" instead of "_index"?
No, you havent missed anything. the "_index" will be replaced by what ever he saves under _index in the if state. So he creates the _index soley for this if state.
@@thelegendarymushroom80 It just seemed odd that he just used "index" or just "i" so when "_index" came out I didn't know if it were for any specific reason.
@@flaminshotgun Understandable! he used "_" to make sure it wouldn't get mixed up with the other "index" that is being used for everything else :)
@@thelegendarymushroom80 he should have named it then -_-
How can I implement keyboard controls to this inventory? I am really lost on what is what.
I actually figured it out. Not sure if the most efficient way (I only needed it to move left and right) but it worked for me, I'll post the code if someone replies needing it.
@@DanteReaver yes please ;)
@@Spoungebobsquarepan ok I'll only get to my PC later today but I'll remember to post the code.
@@Spoungebobsquarepan so here's what I did, in the create event I made a ui_index = 0 variable and a last_selected = 0 variable and also a mouse_on = false. Then on the step I did:
var right = keyboard_check_pressed(ord("D")) ;
var left = keyboard_check_pressed(ord("A")) ;
above the var mx and my, then did:
if mouse_on = false{
var key_move = right - left
ui_index += key_move
if (ui_index < 0) ui_index = inventory_columns -1
if (ui_index > inventory_columns -1) ui_index = 0
if (ui_index != last_selected) audio_play_sound(snd_GemPickup,5,0) // this is just the sound effect
last_selected = ui_index
}
then on the draw GUI I did added a mouse_on = true beneath the part of the code that goes like this
if(is_between(mx, pos_x, pos_x + ui_inventory_box)){
if(is_between(my,pos_y,pos_y + ui_inventory_box)) {
mouse_on = true
// this will activate the mouse and stop you from doing both keyboard and mouse selection, not the best but works for now
and then above that I duplicated the hover code and did if ui_index = if ui_index = inventory_index and mouse_on = false as the condition instead of the stuff above. This will highlight the selection based on a or d input. At last I added the same code we use in the step event of the hover to a Key Press event and switched out the inventory_index var for the ui_index variable with a condition above everything of mouse_on = false.
Dante i've implemented keyboard and gamepad too control for this inventory. Tell to me if you would to know how
I'm having trouble figuring out how to make the items possible to pick up and move anywhere in the inventory. I had a previous system where that was possible and I switched to this one for the recipe tutorial but can't figure it out.
Well you need to move the item sprite to the cursor's position on every frame, and have a get/set for the grid position on the item so you can set it on click. And the square you set it to is whichever one the cursor is inside of. You can do a binary search for the X coordinates and then one for the Y to figure out what square you're in.
@@BusinessWolf1 do you have any idea how you could do this?
The color_border is not set before reading it.
Draw_set(color_border, 1);
at line 15 (for me)
how do i define color_border?
When I was following along, I had a problem with that too. I just set the variables in the create event.
Ex: color_border = c_white.
Obviously, you can change c_white to something else. But that's just a small fix I found.
I am also very new took me a few minutes to figure it out but if you still need an answer.
The color_border is a variable and you are getting the error code because it has not been defined yet. Go into your create tab of obj_inventory and add "color_border = (c_black);
You will also need one for color_background. The color can be whatever you wanted it to be i used black as an example.
Best of luck.
excuse me but i don't think the "is_between" exist... and i'm confused by it. but then i realized it was from a script you made and it wasn't mentioned in your video.
Sorry about that. I'll make sure to go over them all next time
@@GameMakerCasts no problem! thankfully, i downloaded your project and added that tinny script!
@@allaze-eroler so what is the script
@@user-yr2gm5ni4c you can download the project from the description and it's a extremely tiny script! that was this:
function is_between(_value, _min, _max){
return _value >= _min && _value
@@user-yr2gm5ni4c not sure if you still need it but it's
function is_between(_value, _min, _max){
return _value >= _min && _value
It is really confusing tutorial, at least for beginers
Yea i do not recommend learning inventory system so quickly like that
draw_set() did not work for me and i had to use draw_set_color() and draw_set_alpha() separate for each operation.
Please need to know method to save() and load() this thise of struct for this inventory. I cannot figure it out 😢
Try find a way to store the Inventory [ ] array as a json file on the hard drive when they click save, and then load that same json into the inventory when they load again.
Hi Richard, this night i'd found how to save. And works correctly. Soon i will post a link to joystick method to scrolling inventory and save struct. Matharoo give me the solution
how to change game maker theme like in the video?
im using Dracula Theme for GameMaker Studio, but its appears not the same as in video but it close to it ;)
Is it just me or does the system consume quite a lot of performance, for example, from 15 items onwards.
It really shouldn't lol
So hard to follow along. The fact that you would skip typing some of the script was even harder because i had to go back in forth instead of following along as you do it
Also the script doesn't work
is anyone else having a problem with the item_remove(index) function?
nevermind i'm just stupid :/
Hard to follow, 1/3 of the variables aren't shown how they are defined. And if you're tweaking it to fit your own thing without his insane parametres too then forget about it. If you don't already know all this, just don't bother ig lol It's a shame GameMaker won't hire people who can actually explain their code, not just write it out and narrate it.
No "why" question can be answered by this video lol You can practically mute it and get the same info. Atp just stick to the docs
the word "function" is not even a real word anymore
Oq aconteceu o game Maker parou de funcionar em 2022
oque?
oh
I see coding inventory in GameMaker is still a pain and very tedious to do. I thought they were supposed to fix that.
what? since when did they ever say they would make an inventory easier to make?
@@THEELEMENTKING since they mentioned it on their "road map"....
Not happening any time soon, they still don't have a proper UI framework, only a very basic one exclusive for debugging.
Yeah it requires a basic understanding of how structs work, so tedious I can't see how anyone would be able to develop a game.
@@rayujohnson1302 It is tedious. it's always been tedious in GameMaker.
Will the "Game Maker" run on low-end pc?
Depending on how low end you mean, you can always download an old version of GM
My laptop in win7 ultimate run complete gms 2
It runs surprising decent on the new Raspberry pi 5 , stil would suggest something lil more than that tho
purple theme?
meh
GamemMaker doesn't have dictionary?
GameMaker has structs and ds_maps, which both can act like dictionary, if I understand what you mean.
In the video structs are being used already for other stuff, but you could actually use it as for inventory itself. Usually one uses dot syntax for accessing, but you can use strings too. So these are basically equivalent: (inventory.wood) and (inventory[$ "wood"]).
So finding item becomes trivial, you don't need linear lookup but struct acts like hash map.
struct can be used almost exactly like a dictionary. var_name[$ "key"] = value;