To update an item you do:
Inventory.UpdateItemAmount();
Which calls:
SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action);
Which then triggers a call to:
InternalUpdateItemAmount()
Then inside that, you either invoke a call to remove inventory items, or add some. The problem is this process isn't synchronous, and you're using globals in InternalUpdateItemAmount. So this means that if you do multiple UpdateItemAmount() calls on the same Inventory, the globals get overwritten each time before InternalUpdateItemAmount gets called, so only one item will ever get updated (depending on what m_itemToUpdate refers to at the time).
I was trying to update multiple item counts in a cargo container, and only one is ever getting updated, and was completely stumped for awhile.
I made a work around for this by just tossing it into a locked queue. The work around works as expected, and can probably be rolled into the main API. Or you can update with a fix as you see fit.
Here's the main reason:
In SEModAPIInternal.API.Entity.inventoryEntity:
To update an item you do: Inventory.UpdateItemAmount();
Which calls: SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action);
Which then triggers a call to: InternalUpdateItemAmount()
Then inside that, you either invoke a call to remove inventory items, or add some. The problem is this process isn't synchronous, and you're using globals in InternalUpdateItemAmount. So this means that if you do multiple UpdateItemAmount() calls on the same Inventory, the globals get overwritten each time before InternalUpdateItemAmount gets called, so only one item will ever get updated (depending on what m_itemToUpdate refers to at the time).
I was trying to update multiple item counts in a cargo container, and only one is ever getting updated, and was completely stumped for awhile.
I made a work around for this by just tossing it into a locked queue. The work around works as expected, and can probably be rolled into the main API. Or you can update with a fix as you see fit.
Code used for fix: http://pastebin.com/vKERp2hq
Obviously since these are part of the Entity class itself, you won't need the inventoryentity when updating the API.