Game Development Community

TorqueScript - print all the params passed to the current Fn ?

by Orion Elenzil · in Torque Game Engine · 11/14/2007 (2:16 pm) · 2 replies

Does anyone know a handy way to print all the script parameters passed to an arbitrary function ?

i'm picturing something like

function myObj::myFunction(%this, %foo)
{
   echo(getScopeName() SPC "was called with:" SPC getParams());
}

function myOtherFunction()
{
   echo(getScopeName() SPC "was called with:" SPC getParams());
}

function myFinalFunction(%foo, %bar, %bim)
{
   echo(getScopeName() SPC "was called with:" SPC getParams());
}

resulting in
myObj::myFunction() was called with "%this" = "1234" "%foo" = "blah blah".
myOtherFunction() was called with nothing.
myFinalFunction() was called with "%foo" = "something", "%bar" = "something else", "%bar" = "hooray".


(for a description of "getScopeName()" see here.)

my motivation here is to save time and therefore increase the use of thorough debug & error prints to the log.
ie, i want to not have to write out all the params by hand in an error statement.

tia,
ooo

#1
11/14/2007 (3:55 pm)
Not in script, but this would probably be a relatively trivial thing to do in the TS parsing code.

Might be a touch tricky getting the human readable tokens for the locally scoped variables the argument string is stuffed in to, but echoing out the arguments themselves should be trivial.
#2
11/17/2007 (7:17 pm)
Orion, I was thinking of making a function for that, but ... at the moment I'm stuck with what I've submitted in my TDN profile:
function er(%what, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13, %a14, %a15)
{
   if ($Pref::debugOutput) // you can remove this check if you want to have this spam always in your console ;)
   {
      %line = "";
      for(%i=1; %i!=16; %i++)
         if (%a[%i] !$= "")
            %line = %line SPC %a[%i];
      error(%what @ "():" @ %line);
   }
}

function myClass::myTestFunction(%this, %variable1, %variable2, %variable3)
{
   er("myClass::myTestFunction", %this, %variable1, %variable2, %variable3);
   // or
   er(getScopeName(), %this, %variable1, %variable2, %variable3);
}
So, if I made a new function I just do copy-paste of all the parameters (with " , ") and it's it!

function GameConnection::onConnectRequest( %client, %netAddress, %role, %id, %hash, %ver )
{
   er(getScopeName(), %client, %netAddress, %role, %id, %hash, %ver );

And of course it can be extended more or even moved into engine...