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.