如何在保存后立即检索objectId

问题描述:

我正在使用Unity和Parse.com进行游戏开发。我试图找出我保存后立即检索objectId。我曾经尝试这样做:如何在保存后立即检索objectId

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; 

}); 

我上t.Result一个错误说:

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?) 

可以这样以这种方式或其他工作要做。

任何帮助表示赞赏,并在此先感谢:-)

+0

'这是因为任务没有结果property' – CodingDefined 2014-12-02 11:49:43

+0

好了,我不能得到正确的ObjectID回来后保存呢?那么我需要创建一个新的请求? – Mansa 2014-12-02 12:00:03

+2

尝试使用t.Result删除行并在下一行使用myGame.objectID – Reniuz 2014-12-02 12:01:45

只是删除符合t.Result。 使用myGame.objectID获取objectId。

我在检索新创建的ObjectId时也遇到了问题。几个小时(而许多搜索的)后,我能得到下面的代码工作:

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; 
    }