How to Code an Inventory System

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

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

  • @GameMakerEngine
    @GameMakerEngine  Год назад +4

    👾 More int & adv level tutorials: ruclips.net/p/PLhIbBGhnxj5LaEib5NZT4OEy9vK97dVHt

  • @Hunnkiy
    @Hunnkiy 8 месяцев назад +15

    the function is between:
    function is_between(_value, _min, _max){
    return _value >= _min && _value

    • @Monfredini
      @Monfredini 6 месяцев назад +1

      Isso foi muito útil, obrigado 😁

    • @greagorysan1805
      @greagorysan1805 4 месяца назад +1

      appreciate it

  • @DeathByPixelsVisuals
    @DeathByPixelsVisuals Год назад +21

    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!

  • @greagorysan1805
    @greagorysan1805 4 месяца назад +1

    This video is extremely underrated, how did it only get 300 likes? You guys deserve more 😭

    • @bonnymich
      @bonnymich 2 месяца назад

      cuz not many bother most give up gamemaking

  • @ben5852
    @ben5852 11 месяцев назад +6

    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!

  • @camerondavies9659
    @camerondavies9659 10 дней назад

    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

  • @SGTIvan921
    @SGTIvan921 8 месяцев назад +1

    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

  • @cutegamesclub
    @cutegamesclub Год назад +4

    omg so excited to try this tutorial tonight!

  • @myunglee8163
    @myunglee8163 8 месяцев назад +2

    What is your code text font? It looks really nice.

  • @radiocat_
    @radiocat_ 19 дней назад

    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 :)

  • @ackmanstein
    @ackmanstein Год назад +6

    I get to 6:14 and get a bunch of errors when running. Following step by step...

  • @phearedphantom
    @phearedphantom 2 месяца назад

    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)

  • @hec63
    @hec63 4 месяца назад +1

    what do i have to do if i don't want the player to have more items than the number of slots??

  • @Philip-s5m
    @Philip-s5m 6 месяцев назад

    Can open but can't run your file. Getting compile error. What version of Gamemaker you using? BTW its a good tutorial.

  • @ajinkyax
    @ajinkyax 2 месяца назад

    what happened to these videos... I wish you bring more such useful tutorials. #gamemaker

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

    How would I go about adding a row of slots at the bottom of the screen that can hold equipped items?

    • @diegocamacho6060
      @diegocamacho6060 9 месяцев назад +1

      Idk

    • @SynphulHero
      @SynphulHero 9 месяцев назад +3

      @@diegocamacho6060 then don't respond dude. Your comment doesn't help at all.

    • @diegocamacho6060
      @diegocamacho6060 9 месяцев назад +1

      @@SynphulHero yw

    • @raymondfarr3638
      @raymondfarr3638 9 месяцев назад +1

      Idk

    • @BusinessWolf1
      @BusinessWolf1 4 месяца назад +1

      Probably just make a new variable called toolbar which makes a new Inventory() and give it a different UI and grid layout

  • @flaminshotgun
    @flaminshotgun 6 месяцев назад +1

    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?

    • @honeybadger9078
      @honeybadger9078 6 месяцев назад +1

      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.

    • @flaminshotgun
      @flaminshotgun 6 месяцев назад

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

    • @BusinessWolf1
      @BusinessWolf1 4 месяца назад

      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
      @flaminshotgun 4 месяца назад

      @@BusinessWolf1 But since we need to provide the arguments for the script, then why does the script need to be assigned to a variable?

    • @TheMaxqb
      @TheMaxqb 3 месяца назад

      ​@@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?

  • @flaminshotgun
    @flaminshotgun 6 месяцев назад

    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"?

    • @thelegendarymushroom80
      @thelegendarymushroom80 6 месяцев назад +1

      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.

    • @flaminshotgun
      @flaminshotgun 6 месяцев назад +1

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

    • @thelegendarymushroom80
      @thelegendarymushroom80 6 месяцев назад

      @@flaminshotgun Understandable! he used "_" to make sure it wouldn't get mixed up with the other "index" that is being used for everything else :)

    • @BusinessWolf1
      @BusinessWolf1 4 месяца назад

      @@thelegendarymushroom80 he should have named it then -_-

  • @DanteReaver
    @DanteReaver 10 месяцев назад +1

    How can I implement keyboard controls to this inventory? I am really lost on what is what.

    • @DanteReaver
      @DanteReaver 9 месяцев назад +1

      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
      @Spoungebobsquarepan 9 месяцев назад +1

      @@DanteReaver yes please ;)

    • @DanteReaver
      @DanteReaver 9 месяцев назад

      @@Spoungebobsquarepan ok I'll only get to my PC later today but I'll remember to post the code.

    • @DanteReaver
      @DanteReaver 9 месяцев назад

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

    • @renatoramundo5154
      @renatoramundo5154 8 месяцев назад

      Dante i've implemented keyboard and gamepad too control for this inventory. Tell to me if you would to know how

  • @granttjamess
    @granttjamess 6 месяцев назад

    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.

    • @BusinessWolf1
      @BusinessWolf1 4 месяца назад

      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.

    • @MustafaAbbasi
      @MustafaAbbasi 3 месяца назад

      @@BusinessWolf1 do you have any idea how you could do this?

  • @ShiroNyankotv
    @ShiroNyankotv 3 месяца назад +1

    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?

    • @waveknight001
      @waveknight001 3 месяца назад

      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.

    • @theoriginalrage1772
      @theoriginalrage1772 3 месяца назад +2

      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.

  • @allaze-eroler
    @allaze-eroler Год назад +4

    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.

    • @GameMakerCasts
      @GameMakerCasts Год назад +1

      Sorry about that. I'll make sure to go over them all next time

    • @allaze-eroler
      @allaze-eroler Год назад

      @@GameMakerCasts no problem! thankfully, i downloaded your project and added that tinny script!

    • @user-yr2gm5ni4c
      @user-yr2gm5ni4c 10 месяцев назад +1

      @@allaze-eroler so what is the script

    • @allaze-eroler
      @allaze-eroler 10 месяцев назад

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

    • @Planetari233
      @Planetari233 3 месяца назад

      @@user-yr2gm5ni4c not sure if you still need it but it's
      function is_between(_value, _min, _max){
      return _value >= _min && _value

  • @nvm5506
    @nvm5506 6 месяцев назад +3

    It is really confusing tutorial, at least for beginers

    • @salvadorgonzales1
      @salvadorgonzales1 3 месяца назад

      Yea i do not recommend learning inventory system so quickly like that

  • @Goblin_Scout_7777
    @Goblin_Scout_7777 3 месяца назад

    draw_set() did not work for me and i had to use draw_set_color() and draw_set_alpha() separate for each operation.

  • @renatoramundo5154
    @renatoramundo5154 8 месяцев назад

    Please need to know method to save() and load() this thise of struct for this inventory. I cannot figure it out 😢

    • @tigermafia
      @tigermafia 8 месяцев назад +1

      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.

    • @renatoramundo5154
      @renatoramundo5154 8 месяцев назад +1

      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

  • @shylvia2098
    @shylvia2098 11 месяцев назад +1

    how to change game maker theme like in the video?

    • @Spoungebobsquarepan
      @Spoungebobsquarepan 9 месяцев назад

      im using Dracula Theme for GameMaker Studio, but its appears not the same as in video but it close to it ;)

  • @TheNumber01
    @TheNumber01 7 месяцев назад

    Is it just me or does the system consume quite a lot of performance, for example, from 15 items onwards.

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

    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

  • @bardofchaos
    @bardofchaos 9 месяцев назад

    is anyone else having a problem with the item_remove(index) function?

    • @bardofchaos
      @bardofchaos 9 месяцев назад +1

      nevermind i'm just stupid :/

  • @itsmj3103
    @itsmj3103 5 месяцев назад +4

    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

  • @salvadorgonzales1
    @salvadorgonzales1 3 месяца назад

    the word "function" is not even a real word anymore

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

    Oq aconteceu o game Maker parou de funcionar em 2022

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

    oh

  • @robertb67
    @robertb67 Год назад +8

    I see coding inventory in GameMaker is still a pain and very tedious to do. I thought they were supposed to fix that.

    • @THEELEMENTKING
      @THEELEMENTKING Год назад +1

      what? since when did they ever say they would make an inventory easier to make?

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

      @@THEELEMENTKING since they mentioned it on their "road map"....

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

      Not happening any time soon, they still don't have a proper UI framework, only a very basic one exclusive for debugging.

    • @rayujohnson1302
      @rayujohnson1302 Год назад +5

      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.

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

      @@rayujohnson1302 It is tedious. it's always been tedious in GameMaker.

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

    Will the "Game Maker" run on low-end pc?

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

      Depending on how low end you mean, you can always download an old version of GM

    • @TCG-YCHIRO
      @TCG-YCHIRO 10 месяцев назад

      My laptop in win7 ultimate run complete gms 2

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

      It runs surprising decent on the new Raspberry pi 5 , stil would suggest something lil more than that tho

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

    purple theme?

  • @more-or-less-it
    @more-or-less-it Месяц назад

    meh

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

    GamemMaker doesn't have dictionary?

    • @terohannula30
      @terohannula30 Год назад +3

      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.

    • @rayujohnson1302
      @rayujohnson1302 Год назад +1

      struct can be used almost exactly like a dictionary. var_name[$ "key"] = value;