Javascript arrays and structures ?

Hello

I’m getting to the scoring point in my game and i am facing 2 problems.
I don’t know how to make an array in javascript :smile:
and is it possible to have something like
struct blabla
{
long score ;
long playername;
};
in javascript.
if so, is it possible to make an array of a structure ?

Thank you!
Patricia

Making an array is kind of like making a variable, only there’s a bit more to it. You need to define it as an array, a simple code. Also, use *.Length (where * is the array’s name) to change how many variables in the array. To call an array all you have to do is *[^] (where ^ is the variable within the array you want to call) so it goes like this:

var arr = new Array ();



// Add one element
arr.Push ("Hello");

// print the first element ("Hello")
print(arr[0]);

// Resize the array
arr.length = 2;
// Assign "World" to the second element
arr[1] = "World";

// iterate through the array
for (var value : String in arr)
{
print(value);
}
}

I wonder too how to make a structure. Two dimensional arrays? how?

two dimensional arrays can be built up from arrays. try something like this:

var num : int = 5;
var i : int;
var arr2dim : Array = new Array(num);

for(i=0;i<num;i++)
{
arr2dim = new Array(2);
}
this creates a multi dimensioned array
to access the elements of the array just do something like this:
arr2dim[0][0] = “test1”
arr2dim[0][1] = “test2”;
for a structure just create a new class. ex:
class ClassTest
{
var a: int;
var b: float:

}
var testvar = new ClassTest();
testvar.a = 1;
testvar.b = 1.0;