I've stored data in Parse and now I have to access it to create a topTen score for users playing the game allowing a user to only to be shown on the list ones. The data is stored such that each game has a run has a session which has a user with name, pass etc.
So it goes Run Session => User (name, pass, email, etc).
I need to access the name for a user in order to check whether the user is already present on the topTen as well as show the name.
While I can get access to the data on Session I can't reach the data on User.
int counter = 0;
ParseQuery<ParseObject> query = ParseObject.GetQuery("Runs").WhereEqualTo("scoreIdentifier", GameController.instance.scoreContext).OrderByDescending("score");
query.Include("session.user");
query.FindAsync().ContinueWith(t => {
IEnumerable<ParseObject> results = t.Result;
foreach (var item in results) {
if (item.ContainsKey("score")) {
if (counter < 10) {
topTenScores[counter] = item.Get<int>("score");
topTenNames[counter] = item.ObjectId;
ParseObject session = item.Get<ParseObject>("session");
Task<ParseObject> user = session.FetchAsync<ParseObject>();
user.ContinueWith(tt => {
ParseObject userName = tt.Result;
Debug.Log("CHECK FOR TT " + tt.Result.ObjectId);
});
}
if (counter == 9) {
updateTopTen = true;
}
counter++;
}
if (counter < 10)
updateTopTen = true;
}
});
tt.Result.ObjectId writes out the objectId for Session whereas I would think it would be for User.
Any suggestions as to what I'm doing wrong?
I figured it out on my own - the fetchAync() needed a few more iterations:
public void TopTenHighScore() {
int sessionCounter = 0;
ParseQuery<ParseObject> query = ParseObject.GetQuery("Runs").WhereEqualTo("scoreIdentifier", GameController.instance.scoreContext).OrderByDescending("score");
query.Include("session.user");
query.FindAsync().ContinueWith(t => {
IEnumerable<ParseObject> results = t.Result;
foreach (var item in results) {
if (item.ContainsKey("score")) {
if (sessionCounter < 10) {
// --- this is for the overall Score
topTenScores[sessionCounter] = item.Get<int>("score");
ParseObject sessionPointer = item.Get<ParseObject>("session");
Task<ParseObject> session = sessionPointer.FetchAsync<ParseObject>();
session.ContinueWith(tt => {
ParseObject userPointer = tt.Result;
Task<ParseObject> user = userPointer.Get<ParseObject>("user").FetchAsync<ParseObject>();
user.ContinueWith(ttt => {
ParseObject userFinal = ttt.Result;
userNamesList.Add(userFinal.Get<string>("displayName"));
});
});
}
if (sessionCounter == 9) {
sessionCounterDone = true;
}
sessionCounter++;
}
// if the amount of sessions played in total is not above 10
if (sessionCounter < 10)
sessionCounterDone = true;
}
});
}