Forum > Coding >

Creating "Inventory"

WRD

Owner

admin

Posts: 990

Threads: 33

Joined: Dec, 2016

Reputation: 106

Posted

This is made for Matt -
A simple thing you can do is create an associative array containing your objects data, and then looping through them for counting. Below would be a rough example of some kind of gun inventory

std::string guns[] = {
SKS:{"Ammo":20},
M4A1:{"Ammo":40},
M14:{"Ammo":10}
}

#define ARRAY_SIZE(array) (sizeof((array))/sizeof((array[0])))
     
int CombinedMagazineTotal;

for (int i = 0; i < ARRAY_SIZE(guns); i++) {
CombinedMagazineTotal += guns[i];
}
  • 0

I'm just a chill guy fr 🤙

Posts: 345

Threads: 109

Joined: Mar, 2018

Reputation: 37

Replied

👍👍👌👍👍👍👍
  • 0

‏‏‏‏‏

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )