Eliminating duplicates in game inventory

hello.
can please somebody help me with this?
i'm trying to make an inventory that shows items, and display a name and the amount of that item, so if there is duplicates, it does not print them over and over.
here is how i did it, but something is missing and i cant seem to figure it out:

#include "bgt_dynamic_menu.nvgt"
// the menu object that will be used to display the inventory list
dynamic_menu menu;
// i made a class for creating items that has two proprities to make it simple
class item
{
string name;
int amount;
}
void main()
{
show_window("inventory test"); wait(50);
// i made an array of items and gave them a name and an amount
item items(7);
items[0].name="sword";items[1].name="sword"; items[2].name="sword"; items[3].name="dagger"; items[4].name="spear"; items[5].name="club"; items[6].name="axe";
items[0].amount=1; items[1].amount=1; items[2].amount=1; items[3].amount=1; items[4].amount=1; items[5].amount=1; items[6].amount=1;

// now the array of items that will show in the inventory
item inventory;
for(int x=0; x<items.length(); x++)
{
// first, making a new entry in the inventory array that has no value
inventory.resize(inventory.length()+1);
// and now i made the condition that if there is a duplicate, its entry should be removed, and the amount of the original should increas by 1
for(int i=0; i<inventory.length(); i++)
{
if(inventory[i].name==items.name)
{
// +1 to the amount of the original
inventory[i].amount++;
// the last entry should be removed
inventory.remove_last();
}
}
// if the condition is not met and there is no duplicate, everything should go as normal, and the new entry will have the value of a new item
inventory[inventory.length()-1]=items;
}
// and now displaying the inventory using the dynamic menu
// if there are duplicates they should showup only once with a number next to the name of the original showing the amount of them
for(int x=0; x<inventory.length(); x++)
menu.add_item_tts((x+1)+" "+inventory.name+" times "+inventory.amount);
int choice=menu.run("you got "+inventory.length()+" items", true);
}
when i run this script i see that every duplicate is removed yes, but the amount is not modified as expected
i tried as much as my current knowledge of NVGT could take me, but i'm still stuck with this
any help would be appreciated
thank you so much.

Hello! I was exploring the forum topics and found this. I have been asking the same question and there are different answers. Your inventory used the item name as a way to find duplicates.
//Here is how I imagined my solution to be.
#include "bgt_dynamic_menu.nvgt"
dynamic_menu menu;

class item

{

string name;

int amount=0;

//The item must know that it has no amount

}

//The inventory must know how to organize itself

class inventory

{

//An array of items

item content;

//Here is how the inventory handles adding items

void new_item(string name, int amount=1)

{

//It cannot add items that does not exist

if(name==””||amount<=0)

return;

//Count the number of items

int count=content.length();

//Loop through the items

for(int index=0; index<count; index++)
{
//If an item of the same name is found, increase the amount of the item and end the loop

//Both names are lower cased for good comparison

if(name.lower()==content[index].name.lower())

{

content[index].amount++;

break;

}

}
//Otherwise, the item is new and will be added normally

item new;

new.name=name;

new.amount=amount;

}

//The inventory knows how to display itself

int show()

{

//Count the items in the inventory

int count=content.length();

//Run a loop

for(int index=0; index<count; index++)
//Add each item in the menu
menu.add_item_tts((x+1)+" "+content[index].name+" times "+content[index].amount);

//Return the option chosen in the menu
return menu.run(“You got “+content.length()+” items”, true);

}

}

void main()
{
show_window(“Inventory test”);
//Create inventory

inventory i;

//3 swords and 1 of other weapons

i.new_item(“Sword””);

i.new_item(“Sword”);

i.new_item(“Sword”);

i.new_item(“Dagger”);

i.new_item(“Spear”);

i.new_item(“Club”);

i.new_item(“Axe”);

//Show the inventory

i.show();

}

That is all. I hope this can help!