RPG Inventory System: ds_list versus 2D array

C

ChaosX2

Guest
Hi Everyone,

I'm currently in the midst of constructing an algorithm on how to go about creating an inventory system for my RPG. In my game, each character in the party (total 7) has their own inventory in which they can hold a total of fifteen items. So for example, if you want to use a potion, and only player 2 is holding it, then you must access player 2's inventory in the menu or within battle in order to use that specific potion. Which ever data structure I end up using the item will display:

Name of item
Sprite Index
Quantity held by player
Description of Item
Cost of item to buy (if at weapon/item shop)
Type of item (key item, equip, consumable) - not displayed

I'm having issues figuring out what is more efficient. Should I create a ds_list for each member of the party? Should I create a global 2 dimensional array? Or is there another more efficient method I'm not thinking of?

I imagine that when it comes to weapon and item merchants, a ds_list is sufficient to display the game objects and add them to my characters inventory.

Thanks for taking the time to read this :)
Thoughts?
 
A

Aura

Guest
I would personally suggest using a 2D array in this case. You can easily go about using the first dimension for indexes of the items and the second dimension for information related to the items.

Code:
item_info[0, 0] = "Sword";
item_info[0, 1] = spr_sword;
item_info[0. 2] = "A silver sword";
That way you can keep an array for storing information about all the items and another array for holding indexes of the items that you possess. For instance:

Code:
item_ep[0] = 0; //Index for sword
item_ep[1] = 1; //Index for another item
You can take help of Macros to make things more readable. For instance, you can define a macro called iSword of value 0. Now, you can go about using this macro instead of 0 to refer to the sword.

Code:
item_eq[0] = iSword;
Now whenever you require data, use this array:

Code:
draw_text(x, y, item_info[item_eq[0], 0]); //Draw the name of the first item in the inventory
 
A

anomalous

Guest
If you use stackable items, or quality modifiers (Like a [Legendary] Sword, or health potion 45 quantity), just use a 2d structure for both the main inventory table as well as the individual equipment bags.

If you ever intend to search the table of data or sort it, I would just do all that with ds_grid personally, that way its more future proof if you expand it and can make use of ds_grid functions.
 
C

ChaosX2

Guest
Thanks for the feedback you two. I've never looked into the ds_grid functions but I'll check it out.
 
Top