question

edogn12 avatar image
edogn12 asked

How to use the ConsumeItem functon

I am new to this so I am trying to grasp the correct way to do this. I am trying to search through the player inventory for a specific item to get the InstanceId. Then use the InstanceId with the ConsumeItem command.

	public void ConsumePotion() {
		PlayFabClientAPI.ConsumeItem(new ConsumeItemRequest {
			ConsumeCount = 1,
			// This is a hex-string value from the GetUserInventory result
			ItemInstanceId = "How do i get this Value?"


		}, LogSuccess, LogFailure);


	}

I can get the values but I don't know how to use them

	public void GetInventory() 
	{
		PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(),OnGetInventory,error => Debug.LogError(error.GenerateErrorReport()));
	}
	public void OnGetInventory(GetUserInventoryResult result)
	{
		Debug.Log ("Received the following items:");
		foreach (var eachItem in result.Inventory) {


			ItemIds.Add (eachItem.ItemId, eachItem.ItemInstanceId);
			string Instance = ItemIds [eachItem.ItemId];
			Debug.Log(Instance);
		}


	}
Player Inventory
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Hernando avatar image
Hernando answered

It seems you got a way to keep the instanceIds but have difficulty to use it at the right time. If so, this is a C# side programming problem. We recommend that you keep the inventory data in a Dictionary instance and then use the TryGetValue method of it to search the value. Playfab has a good demonstration in the UnicornBattle on github:

https://github.com/PlayFab/UnicornBattle/blob/601906f425a8f4affb693e66da14ac5fde557d59/UnicornBattle/Assets/Scripts/PF_StaticsAndHelpers/PF_PlayerData.cs#L78

https://github.com/PlayFab/UnicornBattle/blob/601906f425a8f4affb693e66da14ac5fde557d59/UnicornBattle/Assets/Scripts/Misc/PlayerUIEffectsController.cs#L259

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.