Using a %Var to get a Object field?
by Chad Kilgore · in Torque Game Builder · 01/25/2009 (12:31 pm) · 2 replies
Is it possible to use a %variable to access an object's field?
Using [url="http://www.garagegames.com/community/resources/view/15077"TScriptArray[/url], I am constructing an array of objects with 2 fields: player and size. I would like to be able to expand TScriptArray's sort functionality and add an extra parameter.
Is this possible? Or is is just a matter of writing a special case?
Using [url="http://www.garagegames.com/community/resources/view/15077"TScriptArray[/url], I am constructing an array of objects with 2 fields: player and size. I would like to be able to expand TScriptArray's sort functionality and add an extra parameter.
function TScriptArray::sort( %this, %compare, %ascending, %field )
{
...
%result = call( %compare, %this.array[%i][b].%field[/b], %this.array[%i+1][b].%field[/b] );
}Then the array could be sorted using the field for comparison, such as:%Array.sort(%compare, %ascending, "player"); %Array.sort(%compare, %ascending, "size");
Is this possible? Or is is just a matter of writing a special case?
Associate Orion Elenzil
Real Life Plus
but if array[%i] is a ScriptObject (or a SimObject of any type),
then the array[%i].%field syntax will give you trouble.
fortunately, you can use eval():