2014-12-02 26 views
2

我正在使用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

回答

0

只是刪除符合t.Result。 使用myGame.objectID獲取objectId。

0

我在檢索新創建的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; 
    } 
相關問題