Unity3D for iOS: Storing a New High Score in Parse via UniParse while Adding a Value to a _ptr Field

So far this is the only way I’ve been able to successfully do this. I wonder if I’m missing something & there’s actually a better way to do this using only 1 call to Parse. Anyone? Feel free to prove me wrong. Please.

// localStorage is a PlayerPrefs instance that lets us grab values stored on the device that's running the app

// MyGameUsers is a Parse Class that stores unique user ID's as the parse Class' objectId's
// change MyGameUsers to your own Class name where appropriate.
var usersTablePointer = new ParseClass("/classes/MyGameUsers");

//"f2H4saD8" is an arbitrary value for demo purposes, a typical objectId from a Parse table  
string myQuery = "where={\"objectId\": \""+ "f2H4saD8" + "\" }";             				
ParseInstanceCollection prseList = gamerTablePointer.List(myQuery);		

//wait to get the Gamer object w/ our objectID specified in myQuery 
while(!prseList.isDone) yield return null;
ParseInstance[] items = prseList.items;		
// post a new record to the Score table in Parse:
// change MyGameScores to your own Class name where appropriate.
var myGameScoresClass = new ParseClass("/classes/MyGameScores");

//create a new record in the db table (represented by the ParseClass)
var myNewScore = myGameScoresClass.New();

//1034 is just an arbitrary score value; you can grab it from your own variable value			
myNewScore.Set( "Score", 1034 ); 	
myNewScore.Set( "MyGameUsers_ptr", items[0] as object );

//create the new record in the server side Parse Class (table) called "MyGameScores" (or your own class name)
//Wait until it's finished the save in Parse.
while(!myNewScore.isDone) yield return null;						

Debug.Log("myNewScore is done; check it in the MyGameScores table in the relevant Parse.com account.");		 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s