【问题标题】:How to retrieve objectId right after save保存后如何立即检索objectId
【发布时间】:2014-12-02 11:45:01
【问题描述】:

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

可以这样或那样做吗?

任何帮助表示赞赏并提前感谢:-)

【问题讨论】:

  • this is because Task does not have Result property
  • 好的,那么保存后我无法立即取回 ObjectID 吗?那我需要创建一个新请求吗?
  • 尝试删除带有 t.Result 的行并在下一行使用 myGame.objectID
  • @Reniuz 我收到一个错误 - 错误 CS0246:找不到类型或命名空间名称“任务”。您是否缺少 using 指令或程序集引用?你能帮我解决这个问题吗?
  • 添加using System.Threading.Tasks;

标签: c# multithreading unity3d parse-platform


【解决方案1】:

我在检索新创建的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;
    }

【讨论】:

    【解决方案2】:

    只需删除带有 t.Result 的行。 使用 myGame.objectID 获取 objectId。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多