Game Development Community

Arrays as dynamic fields

by N.K. · in Torque Game Engine · 01/09/2009 (3:05 am) · 6 replies

Hello everyone,
I was wondering if there was any way to add an array as a dynamic field and initialize it to a certain value. I tried using a for loop in the object initialization but that didn't work.

Cheers,
Numair

#1
01/09/2009 (3:09 am)
datablock PlayerData(BasicBot : PlayerBody)
{  
   mass = 1;
   scorevalue = 5;
   maxDamage = 15;
   weapon = "aiWeaponBasic";
  
  lootTable[0] = HealthPatch; 
  lootTable[1] = 40;
  lootTable[2] = Crossbow;
  lootTable[3] = 3;
  lootTable[4] = rocketLauncher;
  lootTable[5] = 2;
  lootTable[6] = flameThrower;
  lootTable[7] = 1;
   
};

Is that what you are looking for?
#2
01/09/2009 (3:18 am)
So I have to manually declare each element of the array?

Numair
#3
01/09/2009 (5:00 am)
TorqueScript actually creates individual vars out of script arrays, they aren't true arrays.

so:
"MyArray[1]" in script becomes "MyArray1" and MyArray"[1,1]" becomes "MyArray1_1"

But generally speaking, you should be able to operate the script psuedo arrays as you would an array in most C-likes. Now, doing it with a for-loop in a datablock is probably not going to happen. You would need to load it with a for-loop as part of an initialization, but even then I'm not certain exactly how to load it into a dynamic field without a line-by-line...
#4
01/09/2009 (4:40 pm)
I've tried using code like that in datablocks. Doesn't seem to work. A good way to get this approach is to add it to the ::onNew function, or just after where you created it in script. You will be able to use For Loops outside of the datablocks.
#5
01/09/2009 (10:05 pm)
"TorqueScript actually creates individual vars out of script arrays, they aren't true arrays"

Does this mean that if I want to pass an array to a function I have to pass each variable individually?

Numair