Sign In Register

How can we help you today?

Start a new topic

Retrieving data from a nameless 2D array.

Hello,

This is how I create the data.

var chalId = Spark.getData().challenge.challengeId;

var moves = new Array(5);
moves[0] = new Array();
moves[1] = new Array();
moves[2] = new Array();
moves[3] = new Array();
moves[4] = new Array();

Spark.getChallenge(chalId).setScriptData("moves", moves);

 

This is how I upload the data:

var moves = chal.getScriptData("moves");
    moves[0].push(Spark.getPlayer().getPlayerId());
    moves[1].push(Spark.getData().posX);
    moves[2].push(Spark.getData().posY);
    moves[3].push(Spark.getData().dirX);
    moves[4].push(Spark.getData().dirY);
    chal.setScriptData("moves", moves);

 

This is the data in the database:  

"scriptData": {
    "moves": [
      [
        "5943b59186972904e503ef80",
        "5943b576ea0ea4d336f04f19",
        "5943b59186972904e503ef80"
      ],
      [
        1,
        0,
        1
      ],
      [
        1,
        0,
        2
      ],
      [
        0,
        1,
        0
      ],
      [
        -1,
        0,
        -1
      ]
    ],

 

This is my code in Unity to retrieve data:

GSData movesData = data.GetGSData("moves");
List<string> moves_playerId = movesData.GetStringList ("0");
List<int> moves_posX = movesData.GetIntList ("1");
List<int> moves_posY = movesData.GetIntList ("2");
List<int> moves_dirX = movesData.GetIntList ("3");
List<int> moves_dirY = movesData.GetIntList ("4");

 

The problem is that there are no string indexing the data I am trying to retrieve. Is there a way around? Or must I set a string as an index name for each array in the array "moves"? If so, how can I do?

1 Comment

Pardon.

This is the correct way to insert array data: 

var moves = ({ 
    "player" : new Array(),
    "posX" : new Array(),
    "posY" : new Array(),
    "dirX" : new Array(),
    "dirY" : new Array()
    });

 

Login to post a comment