Search Unity

matrix In javascript

Discussion in 'Scripting' started by felipi arena, Jun 18, 2010.

  1. felipi arena

    felipi arena

    Joined:
    Jun 7, 2010
    Posts:
    25
    Hi!

    I was wondering if it is really not possible to create a array of an array (in my country we call it a matrix) in javascript.

    Like:

    var matrix = new type[10][10];

    is that really not possible in JS?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  3. felipi arena

    felipi arena

    Joined:
    Jun 7, 2010
    Posts:
    25
    Sorry to reply again,

    i tried to do what i want in some other way, but is kinda messy.

    What i want is a bidimensional array like:

    |x x x x|
    |x 0 x x|
    |x x x 0|
    |x 0 x x|

    the x will represent the empty position in my grid, the 0 will represent the occupied positions, so would be good to have a bidimensional array for a smart implementation of it.
    I know i can simulate it, but if anyone know if Unity's JS suports it please let me know.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Did you click the link I provided (the first one)?

    --Eric
     
  5. felipi arena

    felipi arena

    Joined:
    Jun 7, 2010
    Posts:
    25
    Oh! that will get it done!

    thanks!
     
  6. montblack

    montblack

    Joined:
    Jul 21, 2010
    Posts:
    3
    I do this:

    class Mapa {
    var id : int;
    }
    function Start (){
    var arr = new Array ();
    arr.Push (new Mapa());
    }
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not sure what that's accomplishing. Also, Arrays are quite slow compared to built-in .NET arrays.

    --Eric