Splitting into 2d array with JS

Hi All,

I have my highscores being returned from a php script and am able to split once on my pipe "|" character but then want to split that into a further 3 items splitting on a "," This will be so that I can layout the items in a nicely formatted manner.

I have tried using this code but it bails on compilation:

    //scoreSplit = scores.Split("|"[0]);
    scoreSplit arrayLists = scores.Split('|'[0]);
    var allArrays : String = new string[arrayLists.Count][];
    for(int i = 0; i < arrays.Length; i++)
        {
        allArrays _= arrayLists*.Split(',');*_
 _*}*_
_*}*_
_*```*_
_*<p>When I run it with the first line uncommented and the rest commented it works fine but obviously its only 1d.</p>*_
_*<p>Any help would be appreciated as to where I am going wrong :)</p>*_
_*<p>regards,</p>*_
_*<p>mm</p>*_

You have more problems than lines of code:

  1. In the uncommented version you try to use a character literal, something for which there is no syntax in Unity js - you should use a indexed character from a `String` literal like you did in the commented version.
  2. What the heck are `scoresplit` and `arrayLists` and how are they related?! If it is a variable, in unity js, you need to use the var keyword and a name, providing static type indication with a colon(:).
  3. You statically type `allArrays` to be a `String` and then assign it an array of string.
  4. `string` is not a valid type in Unity js. You probably meant `String`.
  5. String[] does not have any member `Count`. Did you mean `length`?
  6. You try to declare built-in arrays without a size and this won't work even if there was a proper syntax for 2D arrays in Unity js.
  7. Your for loop is checking against some undefined variable `arrays`.
  8. Again, like 2., what the heck is `i`? See 2. for how to resolve this.
  9. If arrays was supposed to be some kind of array, there is no member Length for Unity js arrays. Did you mean length?
  10. Like 1., because there is no syntax for a character literal in Unity js, this will not work. See 1. for how to resolve this.
  11. For lack of a proper syntax for 2d arrays, Unity js is interpreting your attempt to assign the second dimension of a 2d array of strings as you trying to assign a character to that index of a string at that index in the array. Essentially, the point is that Unity js doesn't do built-in 2D arrays unless they were declared in c#. You will need to use jagged dynamic Unity js `Array` to accomplish your goals.

Working code would look like:

var arrayLists : String[] = scores.Split("|"[0]);
var allArrays : Array = new Array();
for(var i : int = 0; i < arrayLists.length; i++)
    allArrays _= arrayLists*.Split(","[0])*_
_*```*_