Make inventory and sort items
Hello, I’m currently developing a game using GS.
I’m implementing a character’s inventory and have created an inventory table that contains all the items.
In this table, I want the player to be able to select a specific category, such as helmets, and display only the items corresponding to helmets in the list.
For example, the table has columns like itemNo and parts, and I want to show only the items where the parts value is 1
thanks!
Comments
The way I'd do it is:
To explain:
You are looping over the table and checking to see if a given row matches the filter value. If it does, you spawn an actor to display that value.
The display actor saves the current loop row when it spawns (because it's about to change ever iteration of the loop) and uses that value to know what row to display.
Hope that helps!
@adent42 Thanks!
The last bit is to make a rule and a game attribute that destroys / clears all of the inventory actors.
Not sure if this helps. But my approach to this would be using multiple tables.
InventoryDatabase table. Has your item names, types, stats, images, whatever else. This is the fun stuff, the database itself.
PlayerInventory table. This is a list of IDs the player owns (referencing the InventoryDatabase), and maybe quantities if you want that. When the player picks up an item or uses an item, you would add/remove it from this table.
InventoryDisplay table. This is the table used to display stuff on the screen. You dynamically fill this table with filters (show full inventory? show only items from category X?)
So then your logic becomes: constrain actors to InventoryDisplay table and have them display stats based on their ID.
When applying a filter or displaying the screen, you want to create your InventoryDisplay table by emptying it, and then looping over PlayerInventory with your filter.
The reason I prefer this way is it becomes flexible.. you can apply filters, sort, do all kinds of stuff a player might want from a list of items.
@adamhwilk Thank you very much for your response. I've developed this way so far, but I'm asking if there's any other way, and I'm convinced it's not the wrong way.