still cannot decide whether I should use TArray or TMap for inventory and character's action list...

Hello there.

I have been spend nearly 1-2 weeks about deciding of inventories…

why? even though it is simple 2D turn based (like Final Fantasy ish) game… I really need to be careful with how I design inventory and each character’s available action list…

1.there would be 3 types of item types -> Melee Weapons, Ammo, Goods

Melee weapons are weapons can used by characters, but has durability (have not thought about repair).

Ammo is can be used by Ranged weapon (Pipegun and bow…)

Goods is just consumable such as healing item.

Simply I planned 3 types of inventories as these types.

M.Weapon-> TArray, because there can be two or more items with same name, yet different id number and durability.

Ammo -> TMap <FString, class Item>, because i can access it easily by name (FString).

Goods -> TMap <FStrinig, class Item>, because… just like AMMO.

is it sounds good? I been wondering for long time though.

2.Here comes with most difficult design for myself.

there are 3 characters.

Everyone has same command as Fight (or Attack)… each character can use selective items…

For example,

images are temp, don’t tease it plz :frowning:

in character A’s Fight, he (or Player) can select from personal unarmed combo to every melee weapon…

in character B’s Fight, he (or Player) can select from personal unarmed combo to just Ranged weapon (Ammo).

Sounds easy at first, but later I wondered that I need to make another TArray for their available weaponry…

One of reason is… do i really have to transfer again every available weapons or ammo to new TArray?

i think because of their unarmed attack… i could make separate command… but it does not look good…

To Conclude should i make another TArray for selecting actions (unarmed, Melee, e.t.c) in each character?

3.is it possible to make dummy data by easy way such as BP? in BP, i can approach easily putting data, the problem is…

if i put those dummy data (BP) towards inventories which i made as TArray or TMap in c++…

it gets tricky for me.

I am not in the mood for typing every dummy data inside Rama’s Custom Game Instance though by c++ (or coding) though.

Maybe i am feeling sly…

anyway, i may need you guys advice again :confused:

As a suggestion, consider using a TSet for available weaponry.

I am reading TSet documentation right. what is the differences between TArray and TSet? both sounds similar

oh… okay https://www.safaribooksonline.com/library/view/learning-c-by/9781784396572/ch09s03.html

why is that? it has function as not allowing duplicate and… uh… running out of ideas.

I haven’t looked to much into TArray, TSet and TMap yet, but here some general explanation:

Arrays keep their elements in order. And elements are accessed by their index.
So if you wanted to get a specific Item of your TArray you would have to go through all elements of your array and check if this element was your desired one.

Pseudocode:
for (index = 0; index < MyTArray.size(); index++){
Element e = MyTArray[index];
if (e == searchedElement){
return element;
}
}

Sets do not care about the order of their elements. To access an object of a Set, you actually need the object itself since from the object the index is generated to find the element directly.
So you do not need to iterate over the whole array anymore to find an object, you would simply ask “do I have this object”. The Set would generate the index of this object. And if it is there then you know it directly.
You only touched 1 element of your Set! And not all like for the Array.

Sets are really cool if you want to remember e.g. which objects are already done with calculating some stuff. You just want to know if it’s there. E.g. has playerA already joined a team?
The are no duplicates allowed due to the fact, that the index is generated by the object.
If you would try to add the same object twice, both these objects would get the same index and then you couldn’t decide anymore which object was actually the real one. Actually for Sets this shouldn’t hurt, since it would have to be the same object to create such a collision (to generate the same index twice).

A Maps is like a Dictionary.(they are called like this in C#)
Maps consists of Key, Value -Pairs.
You have to know the Key to access the corresponding Value. If you compare it with a regular dictionary. The key would be the word you are looking for. The explanation of the word is the value.

e.g. you have several configurations to generate a level on runtime. These configurations are stored in a Map with Key = String and Value = Configuration.
The cool part about this one is, that you don’t have to know any index of the Configuration, only how you would call it. So if you wanted the configuration of Level “Supercool” you would access it kind of like

Configuration config = MapOfConfigs"Supercool"];

Again like a set access time is kind of instant, since the index is generated through the key. However if you use the same key twice: To which value should the key point then? -> That’s the reason why no duplicates are allowed.

I would suggest to google these names: Array, Hashset, Hashmap

1 Like

i will google them… thanks for your advice.