question

Mehmet Fatih Barut avatar image
Mehmet Fatih Barut asked

How can I wrap GetUserData function

Hi all,

I use Unity and, I am trying to do something like this; (pseudocode)

for (int i = 0; i < length; i++)

{

GetUserData(); (Forexample GoldAmount)

GameObject.Find("Text"+i.toString()).text=GoldAmount;

}

Because it is an async operation and we are not allowed to change UserDataSuccess function I couldn't find how to do it,

How can I do it?

10 |1200

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

Made Wang avatar image
Made Wang answered

Could you please clarify whether the UserDataSuccess function is the OnSuccess callback function of GetUserData method?

What you mean is to define a global variable GoldAmount, assign a value to it in the UserDataSuccess function, and assign its value to text in the loop, is it right? If so, firstly please make sure the variable GoldAmount has been assigned in the OnSuccess callback function of GetUserData method. Otherwise you cannot get the result of the API outside the callback function.

For clarification, the callback function of API request method pre-defined in PlayFab Unity SDK is designed to execute the code in order through nesting the function in the callback function. It will be difficult to execute functions in order if the callback functions weren’t defined correctly. Could you please clarify did your team defines a bool flag to represent the completion status of API request or could you please provide the code of the definition of UserDataSuccess function for our reference?

You can also add a delegated subscription to add callback function you need. This is my sample code.

    Action<GetUserDataResult> action;


    public void GetUserData(string id)
    {
        action = GetUserDataSuccess;
        action += GetUserDataSuccess2;
        PlayFabClientAPI.GetUserData(new GetUserDataRequest
        {
            Keys = new List<string>()
            {
                "GoldAmonut"
            },
            PlayFabId = id
        }, action, GetUserDataFail);


    }
10 |1200

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

Mehmet Fatih Barut avatar image
Mehmet Fatih Barut answered

thanks a lot I'll try it

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.