GameMaker Inventory with Structs | GMS 2.3+ New Features

Поделиться
HTML-код
  • Опубликовано: 9 ноя 2024

Комментарии • 53

  • @GameMakerStation
    @GameMakerStation  4 года назад +11

    Thanks for watching! If there's anything you'd like to see covered (related to 2.3), let me know here!

    • @misterr3083
      @misterr3083 4 года назад +3

      This is great Matharoo, love your videos!

    • @Kezarus
      @Kezarus 4 года назад +3

      Hi Math! How about a best practices video?

    • @GameMakerStation
      @GameMakerStation  4 года назад +5

      @@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 😄

    • @Kezarus
      @Kezarus 4 года назад +1

      @@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. =]

    • @JonPFS
      @JonPFS 4 года назад +1

      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.

  • @theFriendlyGhst
    @theFriendlyGhst 3 года назад +1

    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.

  • @highjindev1155
    @highjindev1155 4 года назад +9

    Thank you for explain construct with specific usage!

  • @soulman902
    @soulman902 4 года назад

    This video is a solid example from Matharoo on why you would want to use Structs and Constructors.

  • @FrankieSmileShow
    @FrankieSmileShow 4 года назад +1

    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.

  • @digitalswordplay
    @digitalswordplay 4 года назад

    Dropping items, equipping items and saving + loading would be awesome next topics to expand off this one :)

    • @digitalswordplay
      @digitalswordplay 4 года назад

      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?

    • @GameMakerStation
      @GameMakerStation  4 года назад +1

      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.

  • @digitalswordplay
    @digitalswordplay 2 года назад +1

    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?

    • @oifridgy
      @oifridgy 2 года назад

      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

  • @m0zzy71
    @m0zzy71 4 года назад +3

    Thanks for the 2.2 examples..!! :)

  • @celesteorsa3918
    @celesteorsa3918 3 года назад +1

    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.

  • @deezyah
    @deezyah 4 года назад +3

    Brilliant tutorial, thank you very much!

  • @MerlorMerlor
    @MerlorMerlor 4 года назад +1

    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

  • @Corilo91
    @Corilo91 3 года назад +1

    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!

  • @DoomedMadhouse
    @DoomedMadhouse Год назад

    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.

  • @projectRaMan
    @projectRaMan Месяц назад

    How to handle picking up multiple objects of the same type, and keeping track of those amounts?

  • @nuclearbeeberman
    @nuclearbeeberman 4 года назад +3

    really good as always !

  • @habarvaz
    @habarvaz 4 года назад +4

    Thanks for the great video!

  • @Ashantic
    @Ashantic 3 года назад +1

    Is there any way to save/load the inventory? I unfortunately do not get it working

  • @netowgtz
    @netowgtz 4 года назад +1

    on point tutorial

  • @astrozombie1983
    @astrozombie1983 4 года назад +1

    Can structs be read in a DS list if saving/loading using json?

    • @GameMakerStation
      @GameMakerStation  4 года назад

      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.

  • @SynphulHero
    @SynphulHero 10 месяцев назад

    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.

  • @habarvaz
    @habarvaz 4 года назад

    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!

  • @eusuntlita4287
    @eusuntlita4287 3 года назад

    can you do this one for the flashing and scaling juice? is not working anymore.

  • @PonoT
    @PonoT 4 года назад

    Thanks for tutorial bro!

  • @frankiejrey
    @frankiejrey 3 года назад

    Can this method replace ds_grid based inventory?

  • @CatLover3000_
    @CatLover3000_ 4 года назад

    I really love your videos

  • @sergeantsuckyduck3271
    @sergeantsuckyduck3271 3 года назад

    Is there a way to make the items stack?

    • @GameMakerStation
      @GameMakerStation  3 года назад +1

      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

  • @VITYAPRO
    @VITYAPRO 3 года назад

    How can I read only one variable of the item (for example, I want the item_name variable to be displayed as text)?

    • @RhythmandPixels
      @RhythmandPixels 3 года назад

      you can call it with a dot after the struct name: draw_text(x,y,item.name)

    • @VITYAPRO
      @VITYAPRO 3 года назад

      @@RhythmandPixels One more question - is there any way I can get all the info from the scripts to a text file?

  • @raffaelechinotti5244
    @raffaelechinotti5244 2 года назад

    3:51 what is that "inventory[| i]"? what does that | means?

    • @GameMakerStation
      @GameMakerStation  2 года назад

      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.

  • @GrrrVahrrr
    @GrrrVahrrr 4 года назад

    Great!

  • @evensteven4367
    @evensteven4367 4 года назад +2

    Your a god

  • @deathzero0212
    @deathzero0212 3 года назад +1

    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.