PDA

View Full Version : [MX2004]array problems



Mythmon
March 10th, 2005, 10:44 PM
Ive been trying to get this piece of code to work



doors = new Array(4);
for (var i=0; i<4; i++) {
myArray[i] = new Array(8);
for (var j=0; j<8; j++) {
myArray[i][j] = new Array(8);
}
}

doors[1][7][6]={newX:1, newY:6, newMap:2};
doors[2][0][6]={newX:6, newY:6, newMap:1};
doors[2][4][0]={newX:4, newY:6, newMap:3};
doors[3][4][7]={newX:4, newY:1, newMap:2};
trace(doors[1][7][6]);


But the trace always comes out to be undefined.

Also, I have searched, and the basis for that code is (working) code from one of the results I found when I searched, any help wuld be appreciated.

Thanks in advance!

mpelland
March 10th, 2005, 11:30 PM
wouldn't you have to define that last array as being an array? i dont' know. i am tired.. :b: :book: :panda:

stringy
March 11th, 2005, 01:27 AM
wouldn't you have to define that last array as being an array? i dont' know. i am tired.. :b: :book: :panda:
Not really sure what you want but maybe
doors = new Array(4);
for (var i = 0; i<4; i++) {
doors[i] = new Array(8);
for (var j = 0; j<8; j++) {
doors[i][j] = new Array(8);
}
}
doors[1][7][6] = {newX:1, newY:6, newMap:2};
doors[2][0][6] = {newX:6, newY:6, newMap:1};
doors[2][4][0] = {newX:4, newY:6, newMap:3};
doors[3][4][7] = {newX:4, newY:1, newMap:2};
trace(doors[1][7][6].newX);

claudio
March 11th, 2005, 06:24 AM
Man you're messing with a 3D array....
doors = new Array(4);
for (var i = 0; i<doors.length; i++) {
doors[i] = new Array();
for (var j = 0; j<8; j++) {
doors[i][j] = new Array();
}
}
doors[1][7][6] = {newX:1, newY:6, newMap:2};
doors[2][0][6] = {newX:6, newY:6, newMap:1};
doors[2][4][0] = {newX:4, newY:6, newMap:3};
doors[3][4][7] = {newX:4, newY:1, newMap:2};
trace(doors[1][7][6]);

mpelland
March 11th, 2005, 06:53 AM
trace(doors[1][7][6][newX]);

Mythmon
March 11th, 2005, 10:13 AM
Do'h, screwed up the variable naming, didn't I?

oh and i know whte way i acces them works, but using the array acces would work as well

thanks for your guys help and quick reply! :te: