console functions
by Nick Carnevalino · in Torque Game Engine · 05/05/2002 (1:29 pm) · 2 replies
ok this has been driving me nutz for a few days now .. i know it's probly somthing simple and i've read the docs about 5 times now ...
here is what i want to do ... i have a class defined in the engine .. and that class has a simple function ( this is a simple fictonal example ) lets say the function called Math::function(int a,int b,int c) looks like this:
if(!c){
a+b=q}
else
{
a+b+c=q;
}
return q;
now i would like to call it on the console like
Addit(1,4); and get the result 5 or Addit(1,4,1); and get 6 .... i cant get the thing to work ... this is the cloesest it have been able to get
i have tried Math.a = argv[1] and the compiler spits that out saying "array type not defined" and i have tried argc ( like the docs say ) and i get compiler arrors about re-defining a predefined type.
i'm just trying to debug some math functions that do work ( i.e. they are properly defined classes even though the example above my not be ) but i cant seem to figure out how to pass console int's to the class then get back the result.
can anyone see anything simple i am missing? or if my assumption that this can even be done is wrong then please let me know.
here is what i want to do ... i have a class defined in the engine .. and that class has a simple function ( this is a simple fictonal example ) lets say the function called Math::function(int a,int b,int c) looks like this:
if(!c){
a+b=q}
else
{
a+b+c=q;
}
return q;
now i would like to call it on the console like
Addit(1,4); and get the result 5 or Addit(1,4,1); and get 6 .... i cant get the thing to work ... this is the cloesest it have been able to get
ConsoleFunction(Addit, int, 2, 3,"Addit(a, b, c);")
{
Addit Math;
int argc;
Math.a = *argv[1];
Math.b = *argv[2];
Math.c = *argv[3];
int result=Math.function();
Con::printf("test");
Con::printf("test2 %d",result);
}i have tried Math.a = argv[1] and the compiler spits that out saying "array type not defined" and i have tried argc ( like the docs say ) and i get compiler arrors about re-defining a predefined type.
i'm just trying to debug some math functions that do work ( i.e. they are properly defined classes even though the example above my not be ) but i cant seem to figure out how to pass console int's to the class then get back the result.
can anyone see anything simple i am missing? or if my assumption that this can even be done is wrong then please let me know.
#2
05/05/2002 (5:50 pm)
thank you :-) ... nothing feels better than bangin your head on a problem then finnaly get it working :-) !!
Associate Tim Newell
Max Gaming Technologies
you need to do:
Math.a = dAtoi(argv[1]);
Math.b = dAtoi(argv[2]);
if (argc > 3)
Math.c = dAtoi(argv[3]);
you also just need to define argc like this:
argc;
no int before it.
you should also use S32 instead of int.
Here is your function rewritten.
ConsoleFunction(Addit, S32, 3, 4,"Addit(a, b [, c] );") { Addit Math; argc; Math.a = dAtoi(argv[1]); Math.b = dAtoi(argv[2]); if (argc > 3) Math.c = dAtoi(argv[3]); S32 result = Math.function(); return result; }Now you can call in the console:echo(Addit(4,1));
-> 5
-Tim aka Spock