GameMaker Studio 2: Simple Inventory Using DS List

Поділитися
Вставка
  • Опубліковано 17 жов 2024

КОМЕНТАРІ • 40

  • @MadJaze
    @MadJaze Рік тому +2

    I cant believe, an inventory that is manageable with the keyboard

  • @digitalswordplay
    @digitalswordplay 3 роки тому +3

    This is incredible! Thank you!!! I’ve watched a lot of inventory tutorials on UA-cam to achieve what you have done and yours is by far the easiest to understand!
    I just had 2 questions. In other tutorials they make use of ds_list_destroy. Should we be doing that at game_end to remove it from memory ?
    Also would you be able to show how to stack the same items when picked up and display a count for them? - Cheers :)

    • @GameMakerRob
      @GameMakerRob  3 роки тому +1

      Digital SwordPlay You're going to want to keep that list active for the whole game so the main thing to do is make sure you only create it once.
      Gamemaker will automatically clean up the list when the game is closed so you don't need to.
      As for stacking - a list only holds one piece of data per entry and to have a quantity, you'd really need each entry to hold more that one piece of data.
      There are many ways to do it and it's down to what you feel most comfortable with.
      How did you want stacking to work exactly? Items auto-stack to a certain number and then a new entry is made if another item of the same type is picked up?

    • @digitalswordplay
      @digitalswordplay 3 роки тому

      @@GameMakerRob Ok good to know about the cleanup! But if game maker automatically cleans up the list would it not be useful to make use of the cleanup event?
      For stacking I was thinking you could pick up 5 potions and they automatically stack onto the same inventory slot. 5 would be the max so that if you tried to pick up a 6th you wouldn’t be able to unless you used one.

    • @GameMakerRob
      @GameMakerRob  3 роки тому +1

      @@digitalswordplay It's useful to use the cleanup event if you're creating/destroying lists during the game. The global.inventory list doesn't need a manual cleanup.
      For stacking - you could have each entry in the global.inventory be for a list, and those secondary lists would hold 2 pieces of information - the item that's stored (0:Key, 1:sword etc) and the quantity.
      When drawing the contents of the list, you could then say var item = global.inventory[| entry][| 0];
      var quantity = global.inventory[| entry][ |1];
      For adding items to the global.inventory, you'd use the line that I have to see if an item of that type already exists in the inventory, if it doesn't, just add a new one with a quantity of 1. If it does already exists, check the quantity, and if the quantity is below the max, just add 1 to the quantity.
      For using items, just -1 from quantity, and always check to see if the quantity is

    • @digitalswordplay
      @digitalswordplay 3 роки тому

      Hey GMR, I was wondering when you have some time if you could quickly take a look at my code as I'm getting an error when picking up an item with my new stackable code. I think the actual stacking code is working ok, but its when I'm drawing the items where I get an error. Would be much appreciated if you could assist :)
      Error // ds_list_find_value argument 1 incorrect type (array) expecting a number
      line 10 (draw gui event) var item = global.inventory[| entry][0];
      This is my step event in the player:
      var item = instance_place(x, y, obj_crops);
      var count = 1;
      if (item != noone and item.can_be_picked_up == true)
      {
      var list_size = ds_list_size(global.inventory);
      for (var i=0; i

    • @GameMakerRob
      @GameMakerRob  3 роки тому

      Digital SwordPlay Can you show the code from the create where global.inventory is setup?

  • @matiasf2824
    @matiasf2824 3 роки тому +1

    Nice tutorial! thanks a lot!

  • @Robin-lg6mz
    @Robin-lg6mz 3 роки тому +2

    Two questions. How would I show item info like (name,price,etc), and what if I wanted the equipped item to stay in the inventory?

    • @GameMakerRob
      @GameMakerRob  3 роки тому +1

      If you don't want the equipped item to stay in the inventory, don't remove it from the inventory when equipping it (but maybe store the entry that the item is in the inventory IN the equipped slot instead.
      If you have some kind of data structure (array/struct/ds_grid etc) that stores data about the items, you can display that information however you like. The important thing to to remember is "each item is a number, that number is an entry in the data structure(s) that store your item information (name/price/etc). Using that number/entry is how you get the info you want".
      You could check out my shopkeeper tutorial that might shed some more light on it: ua-cam.com/video/4QigG77fRus/v-deo.html

  • @dupeyou2474
    @dupeyou2474 3 роки тому +2

    Good!

  • @rlb1968able
    @rlb1968able 7 місяців тому

    Could I possibly make something like this in game maker 8.1

  • @digitalswordplay
    @digitalswordplay 3 роки тому

    Getting an error when I press the backspace button to remove an item... step event for obj_player... unable to find instance for object index - 4 at gml_Object_obj_player_Step_0 (line 133) - remove_item(); Any thoughts?

    • @GameMakerRob
      @GameMakerRob  3 роки тому

      Digital SwordPlay did it work at all or always crash?

    • @digitalswordplay
      @digitalswordplay 3 роки тому

      The game compiles and runs and I can pick up items and move the selector back and forth, but as soon as I press backspace to remove an item, that error pops up. I pretty positive my code is the exact same as yours so I’m not sure what it’s not liking

    • @GameMakerRob
      @GameMakerRob  3 роки тому

      Digital SwordPlay check the script and the step for typing mistakes

    • @digitalswordplay
      @digitalswordplay 3 роки тому

      Figured it out! ... var dropped_item = instance_create_layer(x, y, layer, obj_items); ... for some reason it did not like (layer) so I had to assign it the actual layer I use for items. In my case “Items”. After that it worked flawlessly. Cheers :)

    • @GameMakerRob
      @GameMakerRob  3 роки тому

      @@digitalswordplay That's actually useful to know because I was mentoring somebody else yesterday and they had the same problem - something I haven't seen before.
      I thought it was an issue with MAC's because he used a MAC but maybe it's an issue with 2.3

  • @frankiejrey
    @frankiejrey 3 роки тому

    Hello. Great tutorial. Which font do you use for your client?

    • @GameMakerRob
      @GameMakerRob  3 роки тому

      For the IDE? I think I just increase the size/change the colour of certain things to make it stand out more.

  • @jaech2146
    @jaech2146 3 роки тому

    Is it possible to use a DS map to stack items?

    • @GameMakerRob
      @GameMakerRob  3 роки тому

      What do you mean by "stack" items? Like "quantity"?

    • @jaech2146
      @jaech2146 3 роки тому

      @@GameMakerRob Sorry if I wasn't clear before. I'm talking about using a ds map to stack multiple of the the same item.

    • @GameMakerRob
      @GameMakerRob  3 роки тому

      @@jaech2146 With a ds_map you store values paired with keys. If your value is a list then one of the entries in the list can be quantity.
      I've never actually used ds_maps for that, I would use a list or an array so I order items however I like.

  • @Lemon_Beak
    @Lemon_Beak 3 роки тому

    nice tutorial but is it possible to modify this to make it stack?

    • @GameMakerRob
      @GameMakerRob  3 роки тому

      It is possible to make it stack yes. In your inventory list, instead of just knowing what item it is, it now needs to know what item it is and the quantity of that item in that slot. And each entry in a list only holds one piece of information so that means some changes need to be made.
      -You need to have an array for every inventory slot which holds those two pieces of information.
      -This also means adjusting the code wherever the inventory is mentioned as you'll be accessing data (item or quantity) from an array in the inventory slot, not just the item from the inventory slot.

    • @Lemon_Beak
      @Lemon_Beak 3 роки тому

      @@GameMakerRob oh ok thanks

    • @Lemon_Beak
      @Lemon_Beak 3 роки тому

      @@GameMakerRob im not sure if i can make arrays well im kind of new to gamemaker but i will try

    • @GameMakerRob
      @GameMakerRob  3 роки тому

      @@Lemon_Beak Hit me up on my discord if you get stuck - Discord: discord.gg/8G4kQNV
      This video converts an inventory into being able to have quantity (it's part 2 of another video) - which might give you an idea of how to go about it (Should start playing at the appropriate timestamp):
      ua-cam.com/video/habxYkPNjp0/v-deo.html

    • @Lemon_Beak
      @Lemon_Beak 3 роки тому

      @@GameMakerRob ok thanks