0
Answered

Integrating Inventory with in-game UI

Oliver Marshall 2 weeks ago in Inventory updated by DigitalProphet 2 weeks ago 2

Hi

Is a GC inventory able to be queried via scripts?

I want to have a small inventory (3 or 4 items) and I want those items shown in the main in-game UI, so on the screen in the current game scene. 

I'd need to be able to find the number of items in the inventory, the item names, the thumbnails, and which slots each item is in. 

Can that be done?

Olly

Unity version:
Game Creator version:

Answer

Answer
Answered

Hi Oliver;

Definitely yes. Let me run you on how to do this. The base class from where to access any inventory information is the "InventoryManager". It's a singleton, so it can be accessed from anywhere like this:

InventoryManager.Instance

To access the Player's inventory items you can do it like:


InventoryManager.Instance.playerInventory.items

The "items" property is a Dictionary of type <int, int>. The key of the dictionary represents the ID of the item, and the dictionary's value represents how many of that item is in the player's possession.

Now, to access the item's avatar, name, description and the rest of its properties, you'll need to use that ID and access the item's catalogue. The item's catalogue is also contained inside the singleton instance of the InventoryManager.

For example, if you have a variable called "myItemID" which contains the ID of an item and ant to get the name of that item, do:

InventoryManager.Instance.catalogue[myItemID].itemName.GetText();

Note: Name and description are texts that can be localized, so instead of being a string value, they are LocString (which stands for localized string). In order to get the value of the localized string, use the GetText() method.

That's it. Let me know if you have further questions. Cheers!

Answer
Answered

Hi Oliver;

Definitely yes. Let me run you on how to do this. The base class from where to access any inventory information is the "InventoryManager". It's a singleton, so it can be accessed from anywhere like this:

InventoryManager.Instance

To access the Player's inventory items you can do it like:


InventoryManager.Instance.playerInventory.items

The "items" property is a Dictionary of type <int, int>. The key of the dictionary represents the ID of the item, and the dictionary's value represents how many of that item is in the player's possession.

Now, to access the item's avatar, name, description and the rest of its properties, you'll need to use that ID and access the item's catalogue. The item's catalogue is also contained inside the singleton instance of the InventoryManager.

For example, if you have a variable called "myItemID" which contains the ID of an item and ant to get the name of that item, do:

InventoryManager.Instance.catalogue[myItemID].itemName.GetText();

Note: Name and description are texts that can be localized, so instead of being a string value, they are LocString (which stands for localized string). In order to get the value of the localized string, use the GetText() method.

That's it. Let me know if you have further questions. Cheers!

Hi,

Why not add this as an optional state of displaying the inventory in the Inventory Addon?

Would be great to have some different inventory options.