尝试在我的会话中将玩家对象添加到玩家阵列中

时间:2015-10-21 00:20:03

标签: javascript arrays parse-platform

我正在尝试为我正在制作的网络游戏创建一个大厅,我想将创建大厅的人添加到大厅"玩家&#34 ;阵列。我正在使用解析,但我不能为我的生活找出如何将玩家对象追加到数组中。任何帮助都很棒!

Mapper.CreateMap<OperationSpecification, OperationalScheduling>();

1 个答案:

答案 0 :(得分:0)

您无法理解回调的工作原理。我建议你阅读有关JavaScript回调和承诺的内容。这是应该如何写的:

function createLobby() {
  var ses = Parse.Object.extend("Session");
  var query = new Parse.Query(ses);
  var exists = false;
  query.equalTo("sessionName", document.getElementById("lobby").value);
  query.find({
    success: function(results) {
      console.log("Successfully retrieved " + results.length);
      if (results.length != 0) {
        alert("Session already exists");
        return;
      }
      session.set("sessionName", document.getElementById("lobby").value);
      var Players = Parse.Object.extend("Player");
      var query = new Parse.Query(Players);
      query.equalTo("Name", "testName");
      query.find({
        success: function(results) {
          var query2 = new Parse.Query(Players);
          query2.get(results[0].id, {
            success: function(k) {
              console.log(k);
              session.add("Players", k);
            },
            error: function(object, error) {
              // The object was not retrieved successfully.
              // error is a Parse.Error with an error code and message.
            }
          });
        },
        error: function(error) {
          alert("Error: " + error.code + " " + error.message);
        }
      });
      session.save(null, {
        success: function(object) {
          $(".success").show();
        },
        error: function(model, error) {
          $(".error").show();
        }
      });
    },
    error: function(error) {
      alert("Error: " + error.code + " " + error.message);
    }
  });
}