I've followed the solution suggested above as closely as I can, as I have the same requirements.
I however have the following issue.
I have the following lines as an update function in a script and the token is clearly recognised in my menu label (it also give an exception error when the inventory count is zero - easily fixed, so no problem with that - which again shows that the menu sees the token, but the token is not displaying the actual inventory count, it's just stuck at '1') but it only displays '1' even though my inventory item is set to carry multiple and to carry 5 units on start. The number of items in the inventory decreases by one after every 5 seconds and this is programmed by a timer linked to a trigger. I had hoped that by using the custom token I would be able to have the inventory count decremented in the menu label without having to set a separate global variable just for that, which would be unwieldy since the variable count is being affected by different triggers. Any help?
void Update()
{
int accessCardsCount = AC.KickStarter.runtimeInventory.GetItem(0).count;
First of all, and I'm sure you've checked this but I have to suggest it for completeness, make sure that your access card item indeed has an ID of zero.
The next thing to do is to work out if the fault lies with the token, or the Update function. After the two lines you've posted, insert:
Check the Console window while running - is it correct there? If so, let's see how you're displaying this token. If not, there's an issue with getting the correct count.
Though you have multiple Triggers that decrease the number of cards, an easier way to sync up a variable would be to have a common ActionList asset that each Trigger calls. This ActionList would have both the Inventory: Add or remove and the Variable: Set Action, so that one is not called without the other - and only one of each exists.
Thanks Chris, the ID is indeed '0' and the Debug.Log does not change, it also returns '1' so it's not correct. Thanks for the tip about using the ActionList asset to set the inventory add / remove and count at the same time, I've since learnt about using ActionList assets that way and only wish I had thought about it earlier for handling the inventory because now I have to go back to all those triggers to reprogram them.
Comments
An inventory item's number of units is stored in it's count variable.
You can reference an inventory item by it's ID number, e.g. 4:
int numUnits = AC.KickStarter.runtimeInventory.GetItem (4).count;
The next thing to do is to work out if the fault lies with the token, or the Update function. After the two lines you've posted, insert:
Debug.Log ("Carrying " + accessCardsCount + " access cards.");
Check the Console window while running - is it correct there? If so, let's see how you're displaying this token. If not, there's an issue with getting the correct count.
Though you have multiple Triggers that decrease the number of cards, an easier way to sync up a variable would be to have a common ActionList asset that each Trigger calls. This ActionList would have both the Inventory: Add or remove and the Variable: Set Action, so that one is not called without the other - and only one of each exists.
Amend your Debug.Log to show us some more information:
InvItem item = AC.KickStarter.runtimeInventory.GetItem (0);
if (item != null)
{
Debug.Log ("Carrying item " + item.id + ", label: " + item.label + ", Can carry multiple? " + item.canCarryMultiple + ", Count: " + item.count);
}
What's the output? Please copy/paste it from the Console.