#Loading issue inventory system

1 messages · Page 1 of 1 (latest)

sweet lodge
#

Anyone willing to help me out, I have been stumped for hours. Basically I am loading a saved list of strings and each time I load them, although it should overwrite, it loads it on top of the previous ones there, adding X amount each time. for example if I load 5 times with 3 items initially it goes 3 6 9 12 ... for some reason it does this. I cannot find the root cause of the issue the closest I can get is when Newtonsoft desirializes the object, but that isnt really helpful. The list loaded immediately after deserialization is the extended length (6), even though on the file it is normal (3). Here is some code bits and areas of interest:

https://paste.ofcode.org/yFVTfweVFrpjJccSvcGFfq, https://paste.ofcode.org/5J5HxyMm345yquUsKwiJj, https://paste.ofcode.org/U5DFpN7sEaHzKttYYyQfS7

I'm gonna make this a thread, please if anybody can take a peek at my code and has some valuable insight I would be forever greatful. 🙏

If you have questions or need more code lmk, bed time for me

tribal laurel
sweet lodge
#

Yeah sorry there is a lot of code, the main code i am talking about is this section:

    public void LoadData(Data data)
    {
        Inventory.LoadItems(((InventoryData)data).itemNames);

        UpdateInventoryUI(InventorySlots);
    }

essentially this gets called from the saver/loader to load the data back in, it essentially sets the Items in the inventory to be the saved list that it retrieves (called itemNames) in code, which when it deserializes the JSON it ends up duplicating it somehow.

#

It is kinda hard to understand it without the whole scope of code

#

basically here

Inventory.LoadItems(((InventoryData)data).itemNames);

the loaded data gets turned into InventoryItemData and then the list is accessed, at this point the list is added onto what already existed. E.G. If i save with 2 springs, and then load with the 2 springs still in my inventory, i now have 4 springs, when it should overwrite and keep me at 2. I have tried so much to try and get it to clear the items before loading but even when it clears it still remembers somehow the old items

sweet lodge
#

image right after json is got from file:

#

after deserializing:

#

i had 3 in my inventory, but if its reading from the file it shouldnt matter whats in my inventory, not sure how its getting that data