0

Using the code below, I am able to return a single LeaderboardScore back to Unity, however what I want to do is to return scoreResults and end up with a list of LeaderboardScores in Unity.

I am not sure what type I need to specify on the Unity side to make this happen. I would assume that it would just be IDictionary<string,object>[] since Parse.Query.find returns an array of ParseObjects, however when I do that t.IsFaulted is true, but no error messages or codes are printed (I think it may be having some trouble casting to ParseException).

If someone can shed any light on what needs to be done here I would really appreciate it :)

Cloud Code

Parse.Cloud.define("getFriendsScores", function(request, response)
{
    // code to get friends

    var scoresQuery = new Parse.Query("LeaderboardScore");
    scoresQuery.containedIn("user", parseFriends);

    scoresQuery.find(
    {
        success: function(scoreResults)
        {
            response.success(scoreResults[0]);
        },
        error: function(scoreError)
        {
            console.log('No matching scores found...');
        }
    });
}

Unity Code

ParseCloud.CallFunctionAsync<IDictionary<string, object>>("getFriendsScores", parameters).ContinueWith(t =>
{
    if (t.IsFaulted)
    {
        foreach (var e in t.Exception.InnerExceptions)
        {
            ParseException parseException = e as ParseException;
            Debug.Log("Error message " + parseException.Message);
            Debug.Log("Error code: " + parseException.Code);
        }
    }
    else
    {
        Debug.Log("Success!");
    }
});

1 Answer 1

1

Managed to get it working by using the following type in Unity:

<IList<IDictionary<string, object>>>

A single ParseObject is returned as an object that implements IDictionary<string, object>, and when you ask for a list, it gives you a List of those (I just used IList because it is more generic).

For anyone else struggling with figuring out the return type of these kind of functions, just do something like this and you'll work it out:

ParseCloud.CallFunctionAsync<object>("functionName", parameters).ContinueWith(t =>
{
    Debug.Log(t.Result.GetType().ToString());
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.