Game Development Community

Passing array from engine to script

by Colossai Studios · in Torque Game Engine · 05/02/2005 (2:43 am) · 4 replies

Is there any way to achieve this?

I've tried to use a console function to return the array like this:

ConsoleFunction( InitAiManager, Array, 1, 1, "test")
{
   ....
    return AiManager::mUnitArray;
}

but that won't compile

"cannot convert parameter 3 from 'Array (SimObject *,S32,const char ** )' to 'StringCallback' "

This happens because Array isn't included in consoleTypes.h. Does this means that only those types are possible to pass from the engine to Torque scripts?

I've also tried addVariable on the array but doesn't compile either for the same reason.

Any way around this???

#1
05/02/2005 (4:59 am)
I've tried using the type TypeS32Vector to pass an vector of integers, but when received in TS it seems to be just a string, which isn't very handy. But I'll guess I could extract the values from there if no better way exists.
#2
05/02/2005 (9:10 am)
IIRC, You can only return these types from a ConsoleMethod/ConsoleFunction:

const char *
S32
F32
bool
void
#3
05/02/2005 (10:19 am)
@Joakim - Extracting the values from the string is how you're supposed to do that sort of thing. It's actually very simple to parse with GetWordCount and GetWord doing the heavy lifting:

function AverageValues(%Values)
{
   // %Values is a text string of integers.
   %Count = GetWordCount(%Values);

   %Average = 0;

   for(%v = 0; %v < %Count; %v++)
   {
      %Average = %Average + GetWord( %Values, %v );
   }

   return %Average / %Count
}

How much slower/faster this is than processing them out of an array... no clue.
#4
05/02/2005 (5:16 pm)
It's a little slower but you shouldn't be doing heavy math in script anyway.