Game Development Community

Array question

by Ronald J Nelson · in Torque Game Engine · 10/01/2007 (11:07 pm) · 9 replies

Its been a while since I have been to college so my mind is getting a bit rusty.

My question is, is it possible to have an array of arrays?

For instance I have 6 groups of 6 datablocks to be accessed. I want to have an array that can be used to access which of the arrays is appropriate at the time.

#1
10/01/2007 (11:11 pm)
You could add the datablocks to a simset, then all your simsets to a master simset or simgroup.
#2
10/02/2007 (12:36 am)
Have you tried using a 2 Dimension Array ?

$array[%indexSet1 , %indexSet2] = %data ;
Aun.
Mayan Software
#3
10/02/2007 (11:17 am)
Does anybody know how many dimensions TorqueScript's arrays can take?
#4
10/02/2007 (12:17 pm)
Quick test yields at least 18, possibly unlimited.
#5
10/02/2007 (12:18 pm)
Bear in mind that "$myArray[1, 2, 3, 4]" is really just shorthand for "$myArray_1_2_3_4".
#6
10/02/2007 (5:25 pm)
Well actually it doesn't exactly work that way
Torque allows u to create variables in runtime & it also allows u to build the variable name
what i mean is arrays in torque script are not more than variables whom their name was built in the runtime.
(still not clear .. ofcourse :D )
as Orion mentioned that $myArray[1,2,3,4] is actually $myArray1_2_3_4 (no '_' before the '1') to be exact
the "[ ]" are like concatenation operators for variable names
so what arrays are really not more than just normal variables with normal names that u can treat them virtually as arrays as in other languages that ppl are used to (actually every language uses this syntax for arrays)
so to answer the last question u may want to ask:
whats the max size for a variable name ?? :D

I hope that was clear (in a way :D, although I kinda doubt that hehe :D)
#7
10/02/2007 (6:03 pm)
Well I was kind of hoping to do this in code rather than script. But I do like the idea.
#8
10/02/2007 (6:34 pm)
Lol !

you mean this ?

int myArray[100][100][100][100];

is an array of 100 arrays of 100 arrays of 100 arrays of 100 ints.
#9
10/02/2007 (7:23 pm)
Yeah I got that, thanks Orion. However since I am using this in my projectile code, I have a small problem.

This line:

addField("decals", TypeDecalDataPtr, Offset(decals, ProjectileData), NumFX,NumDecals);

I am setting this up for multiple bullet holes per material that can be randomly slelcted when fired.

Most of the code other than adding the 2 Dimension Array is pretty similar to original.

Here is my .h code.
enum fxConstants {               
      NumFX = 20,// Number of fx types constant
	  NumDecals = 6, // # of loaded Decal Datablocks
   };

   DecalData* decals[NumFX][NumDecals];       // Decal Datablocks
   S32 decalId[NumFX][NumDecals];             // Decal IDs

   ExplosionData* explosionDT[NumFX];       // Explosion Datablock
   S32 explosionIdDT[NumFX];             // Explosion IDs

As you can see I didn't see the need for multiple explosions per material, just one per material will do.

Like I said other than having to add an addition for statement here and there to set up each decal for each material to NULL, I just need to figure out what I did wrong so I can get this one line working.