@@Kezarus I would say it's too early for that, 2.3 just came out and I myself have been trying to figure out good practices, let alone best practices 😄
@@GameMakerStation, I have the same struggle in the past versions too. And it's always a good reminder of good things that could be done. Or done ina a better way. But thanks for the content, mate! I will stay tunned for more. =]
It didnt impreved much, in the previous version you can still create a variable in the object then changing it in the level editor ( ex: bulletType = bullet1, bullet2...bullet3...etc.. "instance_create"bulletType " )... Anyway if you could make a tutorial about better animations that would make day :D... An animation action/soundEffect shouldnt play on a key press or animBegin or animEnd, but instead on a specific frame of that animation.
Big thanks for all your videos on game maker studio 2.3, these have been very helpful for converting my project and getting started with the new version's features.
Follow up, with this new system, once you collect an item ie the bow in your example, how would you loop through the list to find it if you needed to know that it exists in the inventory?
You can store the item reference (from the enum) in the inventory list, and just pull the data from the global structs whenever you need them. So this way you can check the enum reference in any slot in the list.
Hey Gurpreet, I want to stack items using this method. Would you be able to tell me if I'm on the right track? 1. Declare "amount" in the constructor. 2. Add "1" as the amount in the struct for a potion. 3. In the player step event, loop through the inventory to see if potion is already in the inventory. 4. If item is in inventory, += 1 to potion else { add function } 5. Draw GUI event: within loop for displaying text for item, add second draw text line to display item amount. Thoughts?
Thanks for the tutorial! It would be nice if there were English subtitles too, so I can better understand what you do, unfortunately I can't understand spoken English.
great tutorial, very easy to understand, much apreciated! however i'm having some trouble applying this to my game and was hoping you could shed some light: so i have saved my constructors into global variables as you did. i then ad those variables (constructors for knife and gun) into my inventory ds_list. now on a weapon switch, i want to apply all the variables from my ds_list entry for gun to the calling object (sprites, current_ammo etc.). normaly i'd run the constructor function like scr_gun(); but how can i do this with my ds_list entry? cheers
This is awesome! Just one question. I've made an inventory system that uses ds_grids to organize all the info about items, ending up with hundreds of functioning but disorienting lines. I use this method: var item = inv_grid[# 0, ii] var item_name = info_grid[# 0, item] -> draw_text(item_name) var item_description = info_grid[# 1, item] -> draw_text(item_description) var item_color = info_grid[# 2, item] -> draw_text(item_color) and so on for all other values, like price, level, power, etc... How could I adapt my system to get all the values from the structs instead? Thank you for any advice!
I know the Draw GUI event in the inventory object doesn't matter as much since that's just testing to see the structs but I'm trying to do that myself and for some reason, even though I've copied your script 1:1, it's showing two lines of the same item.
Are you using json_encode? I don't think that saves structs. The GMS 2.3.1 beta has functions for saving/loading structs/arrays (json_stringify() and json_parse()). Do note that the beta may corrupt your project, so tread carefully.
Hey man, I'm having some issues with converting my project to 2.3, and I thought you might be able to help. Do you offer any personal assistance with this stuff? Thanks!
You can add a "count" variable to the item struct. When adding an item to the inventory, first check if it already exists there, and then simply increase the count instead of adding a new struct. I have a separate (albeit older) video on stackable inventory, it uses arrays but the same concept can be applied to structs. ruclips.net/video/Eh39oeDk76Y/видео.html
It's used to get an item from a DS List. For regular arrays you'd use inventory[i], but for DS Lists, you put the "|" in there to tell GML that it's a DS List, and not an array.
Great job on explaining how structs and constructors work... but in the context of this video, this approach makes little sense. You briefly mention that at the end of the video, that basically you are creating a bunch of data structures for every single instance of every item in the game, even though those items' variables are static. This is highly inefficient and bad advice. Your alternative method makes more sense, each item template gets a struct but not each instance of an item. However, even than, you are simply using arrays once again, defeating the purpose of using structs really. I don't think structs are useful for most inventory systems. Arrays or data structures are better approaches. However, I do want to point out a case where you WOULD want to use constructors for an inventory system. If you have a complex upgrading system for your weapons/armors than a constructor approach would work wonders, since every single instance of a weapon IS unique in that case, they can all hold unique information about their upgrade path and what not. Likewise for games that have randomized weapons, like "Broadsword" can spawn as "Swift Broadsword" or "Deadly Broadsword" with stat differences and additional effects. So it really comes down to what your individual game NEEDS. Don't use a programming technique that is counter-intuitive to the problem you're trying to solve or feature you're trying to implement. There are many different tools in the toolbox that a programmer needs to learn how to use, but it's also just as important learning WHEN to use which tool. Anyway that's just me nitpicking. Overall a solid tutorial for those who want to learn the basics of structs in GMS2.
Thanks for watching! If there's anything you'd like to see covered (related to 2.3), let me know here!
This is great Matharoo, love your videos!
Hi Math! How about a best practices video?
@@Kezarus I would say it's too early for that, 2.3 just came out and I myself have been trying to figure out good practices, let alone best practices 😄
@@GameMakerStation, I have the same struggle in the past versions too. And it's always a good reminder of good things that could be done. Or done ina a better way.
But thanks for the content, mate! I will stay tunned for more. =]
It didnt impreved much, in the previous version you can still create a variable in the object then changing it in the level editor ( ex: bulletType = bullet1, bullet2...bullet3...etc.. "instance_create"bulletType " )... Anyway if you could make a tutorial about better animations that would make day :D... An animation action/soundEffect shouldnt play on a key press or animBegin or animEnd, but instead on a specific frame of that animation.
Coming back to game maker after not using it since GMS1 and this is so great. GML has needed this for a long time now.
Thank you for explain construct with specific usage!
This video is a solid example from Matharoo on why you would want to use Structs and Constructors.
Big thanks for all your videos on game maker studio 2.3, these have been very helpful for converting my project and getting started with the new version's features.
Dropping items, equipping items and saving + loading would be awesome next topics to expand off this one :)
Follow up, with this new system, once you collect an item ie the bow in your example, how would you loop through the list to find it if you needed to know that it exists in the inventory?
You can store the item reference (from the enum) in the inventory list, and just pull the data from the global structs whenever you need them. So this way you can check the enum reference in any slot in the list.
Hey Gurpreet,
I want to stack items using this method. Would you be able to tell me if I'm on the right track?
1. Declare "amount" in the constructor.
2. Add "1" as the amount in the struct for a potion.
3. In the player step event, loop through the inventory to see if potion is already in the inventory.
4. If item is in inventory, += 1 to potion else { add function }
5. Draw GUI event: within loop for displaying text for item, add second draw text line to display item amount.
Thoughts?
how did you exactly checked the existence of the item in the loop? i guess it's from the enum struct, but my code just doesn't work
Thanks for the 2.2 examples..!! :)
Thanks for the tutorial! It would be nice if there were English subtitles too, so I can better understand what you do, unfortunately I can't understand spoken English.
Brilliant tutorial, thank you very much!
great tutorial, very easy to understand, much apreciated!
however i'm having some trouble applying this to my game and was hoping you could shed some light:
so i have saved my constructors into global variables as you did. i then ad those variables (constructors for knife and gun) into my inventory ds_list. now on a weapon switch, i want to apply all the variables from my ds_list entry for gun to the calling object (sprites, current_ammo etc.). normaly i'd run the constructor function like scr_gun(); but how can i do this with my ds_list entry? cheers
This is awesome! Just one question. I've made an inventory system that uses ds_grids to organize all the info about items, ending up with hundreds of functioning but disorienting lines. I use this method:
var item = inv_grid[# 0, ii]
var item_name = info_grid[# 0, item] -> draw_text(item_name)
var item_description = info_grid[# 1, item] -> draw_text(item_description)
var item_color = info_grid[# 2, item] -> draw_text(item_color)
and so on for all other values, like price, level, power, etc...
How could I adapt my system to get all the values from the structs instead?
Thank you for any advice!
I know the Draw GUI event in the inventory object doesn't matter as much since that's just testing to see the structs but I'm trying to do that myself and for some reason, even though I've copied your script 1:1, it's showing two lines of the same item.
How to handle picking up multiple objects of the same type, and keeping track of those amounts?
really good as always !
Thanks for the great video!
Is there any way to save/load the inventory? I unfortunately do not get it working
on point tutorial
Can structs be read in a DS list if saving/loading using json?
Are you using json_encode? I don't think that saves structs. The GMS 2.3.1 beta has functions for saving/loading structs/arrays (json_stringify() and json_parse()). Do note that the beta may corrupt your project, so tread carefully.
I'm having an issue where the inventory is being drawn, but it has 9 additional lines of numbers (0-8) being drawn as well.
Hey man, I'm having some issues with converting my project to 2.3, and I thought you might be able to help. Do you offer any personal assistance with this stuff?
Thanks!
can you do this one for the flashing and scaling juice? is not working anymore.
Thanks for tutorial bro!
Can this method replace ds_grid based inventory?
Yup
I really love your videos
Is there a way to make the items stack?
You can add a "count" variable to the item struct. When adding an item to the inventory, first check if it already exists there, and then simply increase the count instead of adding a new struct. I have a separate (albeit older) video on stackable inventory, it uses arrays but the same concept can be applied to structs. ruclips.net/video/Eh39oeDk76Y/видео.html
How can I read only one variable of the item (for example, I want the item_name variable to be displayed as text)?
you can call it with a dot after the struct name: draw_text(x,y,item.name)
@@RhythmandPixels One more question - is there any way I can get all the info from the scripts to a text file?
3:51 what is that "inventory[| i]"? what does that | means?
It's used to get an item from a DS List. For regular arrays you'd use inventory[i], but for DS Lists, you put the "|" in there to tell GML that it's a DS List, and not an array.
Great!
Your a god
you're*
Great job on explaining how structs and constructors work... but in the context of this video, this approach makes little sense. You briefly mention that at the end of the video, that basically you are creating a bunch of data structures for every single instance of every item in the game, even though those items' variables are static. This is highly inefficient and bad advice. Your alternative method makes more sense, each item template gets a struct but not each instance of an item. However, even than, you are simply using arrays once again, defeating the purpose of using structs really.
I don't think structs are useful for most inventory systems. Arrays or data structures are better approaches. However, I do want to point out a case where you WOULD want to use constructors for an inventory system. If you have a complex upgrading system for your weapons/armors than a constructor approach would work wonders, since every single instance of a weapon IS unique in that case, they can all hold unique information about their upgrade path and what not. Likewise for games that have randomized weapons, like "Broadsword" can spawn as "Swift Broadsword" or "Deadly Broadsword" with stat differences and additional effects.
So it really comes down to what your individual game NEEDS. Don't use a programming technique that is counter-intuitive to the problem you're trying to solve or feature you're trying to implement. There are many different tools in the toolbox that a programmer needs to learn how to use, but it's also just as important learning WHEN to use which tool. Anyway that's just me nitpicking. Overall a solid tutorial for those who want to learn the basics of structs in GMS2.