如何在保存后立即检索objectId
我正在使用Unity和Parse.com进行游戏开发。 我试图弄清楚我在保存后立即检索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?)
这可以通过这种方式或其他方式完成。
任何帮助表示赞赏并提前感谢:-)
我在检索新创建的ObjectId
遇到了问题。 几个小时后(以及大量的搜索)我能够得到以下代码:
public static async Task 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; }
只需使用t.Result删除行。 使用myGame.objectID获取objectId。