Game Development Community

Cant support N-dimension array?[answered

by Chok Wei Tat · in Torque Game Builder · 10/16/2006 (4:46 pm) · 3 replies

Hi, can someone tell me what is wrong?

Worked
function Board::initSpawnState(%this) {
for(%i = 0; %i < %this.getTileCountX(); %i++) {
for(%j = 0; %j < %this.getTileCountY(); %j++) {
%gBoardSlotRespawnState[%i] = 0;
}
}
}

Error
function Board::initSpawnState(%this) {
for(%i = 0; %i < %this.getTileCountX(); %i++) {
for(%j = 0; %j < %this.getTileCountY(); %j++) {
%gBoardSlotRespawnState[%i][%j] = 0;
}
}
}

Thanks

#1
10/16/2006 (4:50 pm)
The syntax for multi-dimension arrays is not [ A ][ B ] in Torque script, it's [A,B] so your example should be

%gBoardSlotRespawnState[%i,%j] = 0;

Also be aware that the gBoardSlowRespawnState you've created above is a local variable and will not be accessable outside the initSpawnState function. You can however make it into a global variable by using $ instead of %. Or you could make the variable a member of your board class instance eg

%this.gBoardSlotRespawnState[%i,%j] = 0;

Then where ever you can access your specific instance of the board, you can access the respawn state member.
#2
10/16/2006 (4:53 pm)
Oh!, thanks! :p

and thanks again for reminding me, i m planing to use

%this.gBoardSlotRespawnState instead of %gBoardSlotRespawnState, coz just to debug on the script
#3
10/16/2006 (9:40 pm)
Alternatively you can access %array[1,1] by %array1_1

Tag: TGB in GPGT