Building an RPG-Style Inventory

22

Index

Attached Files

The following files have been attached to this tutorial:

.c3p

inventory-system.c3p

Download now 344.98 KB

Stats

11,888 visits, 33,559 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

The project runs on a single layout split into three layers – the 'game', a layer to display some text and the inventory itself. On the game layer, sits the player object and the item boxes used to add items to the inventory. The text layer is simply a 0% parallax layer to show the player what item they’ve picked up. The inventory is stored on its own layer so that it can be called when it's needed, the rest of the time it's invisible.

The player object is simply a square sprite with the tile movement behavior. The item boxes are also square sprites, however, these are static and have several instance variables to define what item(s) is stored within them. There are two variables to define the item itself, ItemID and Item Name – both the string and numeric ID are needed for separate things. There's a variable to define which category the item belongs to and one to define how many of the item are in the box. When the player picks up an object, a text object will be made briefly visible to show what’s been picked up, before fading out.

The inventory itself is made up of several different objects. Laid out on a background are twenty ItemSlot objects which act as the slots for the inventory. On the right-hand side is an item description box as well as a display slot to show a larger image of the currently selected item. The current inventory category is shown above the item slots.

The ItemSlot object has a couple of instance variables assigned to it: SlotID and ItemID. SlotID is used to determine where the cursor should sit (in conjunction with the CurrentItemSlot global variable) and ItemID tells the slot what item is currently in it. A lot of the other objects are cosmetic, aside from the text objects. The text for the item name and description is set from the JSON file which stores all the item information, while the number held text object uses the dictionary object.

  • 10 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Seriously one of the best tutorials/guides on Construct. This should have won some awards! :)

    My question is, next step, how would you set this up so that certain items are only available based on your character's level? Obviously you would need some value to increase (XP?) and when it hit a certain value (level?), new items could be "found" but putting that together is beyond me. However, for a superhero like Laura_D, it could be a fun project building off this gem.

    Thanks for all that you do!!

  • Hi Laura! I'm struggling to understand where the images for the items are being pulled in from. I don't see it mentioned in the tutorial. Could you please explain? Thanks!

      • [-] [+]
      • 1
      • Laura_D's avatar
      • Laura_D
      • Construct Team Community Manager
      • 1 points
      • (1 child)

      So, both the ItemShowcase and the ItemSlot objects have animation frames for each item. Then, in the JSON file, each item has an ID and these ID numbers dictate the order that the frames are stored in on the Showcase and Slot sprites.

      The Slot images are set from these ID numbers in the Inventory Category Settings event group, and the Showcase images are set during the UpdateInv function.

      Does that help?

  • Thanks for the tutorial Laura! Just a question, is there any reason you specify the items on a JSON file?

    Feels to me that it would be easier to manage if they were created individually under a folder or family since we load the json to memory anyway, unless there is a performance gain I'm missing.

      • [-] [+]
      • 2
      • Laura_D's avatar
      • Laura_D
      • Construct Team Community Manager
      • 2 points
      • (0 children)

      I've not done any testing in terms of performance, but for me, it was down to preference. I didn't want to have loads of different objects even if they were nicely sat in a folder! I assume it would still work using a different object for each item, but I've not tried it!

  • we know that CategoryName is an instance variable of the array(inventory) but where did ArrayName come from?

    edit:o, i just now know it, we can add a thing called parameter in the function.

  • i hope the no. of events is not greater than 50 cause i havent bought construct yet. maybe i can cut down some events for strings.

  • Load more comments (2 replies)