Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve objectId right after save

I am using Unity and Parse.com for my game development. I am trying to figure out I retrieve the objectId right after save. I have tried this:

ParseObject myGame = new ParseObject("Games");
myGame["score"] = 223;
myGame["playerName"] = "Michael";
Task saveTask = myGame.SaveAsync().ContinueWith(t => {

    ParseObject theObject = t.Result;
    string newObjectId = theObject.objectId;

});

I get an error on the t.Result saying:

Type `System.Threading.Tasks.Task' does not contain a definition for `Result' and no
extension method `Result' of type `System.Threading.Tasks.Task' could be found (are
you missing a using directive or an assembly reference?)

Can this be done in this way or another.

any help is appreciated and thanks in advance :-)

like image 489
Mansa Avatar asked Dec 07 '25 22:12

Mansa


1 Answers

I was also having problems with retrieving the newly created ObjectId. After a few hours (and a lot of searching) I was able to get the below code to work:

    public static async Task<string> CreateNewGame()
    {
        string newObjectId = null;

        ParseObject myGame = new ParseObject("Games");
        myGame["score"] = 223;
        myGame["playerName"] = "Michael";

        await myGame.SaveAsync().ContinueWith(
              t =>
              {
                  newObjectId = myGame.ObjectId;
              });

        return newObjectId;
    }
like image 139
Ravi Ram Avatar answered Dec 09 '25 13:12

Ravi Ram