Game Development Community

ConsoleMethod problem

by Anthony McCrary · in Torque Game Engine · 05/19/2002 (4:03 pm) · 10 replies

I can't seem to get the ConsoleMethod to actually add the method to the console.



bool muscleCar::gearShiftUp() {


	if(mDataBlock->currentTransmissionGear == 5) {

		return false;

	} else {

		mDataBlock->currentTransmissionGear++;
		return true;
	}

}

ConsoleMethod(muscleCar, gearShiftUp, bool, 2, 2, "obj.gearShiftUp()")
{

	muscleCar* car = static_cast<muscleCar*>(object);
 
	bool shiftResult = car->gearShiftUp();

	if(shiftResult) {

		return true;

	} else {

		return false;

	}

   
}

Could someone point out what I am doing wrong? thanks

*changed the 1,1 to 2,2 still no dice*

#1
05/19/2002 (4:10 pm)
Ok,
ConsoleMethod(muscleCar, gearShiftUp, bool, 1, 1, "obj.gearShiftUp()")
is the problem, im sure you'll need at least a 2, 2
that should work.
Edit:
Quote:
In this case, the first argument is the name of the class, followed by the arguments to ConsoleFunction. These macros create a function declaration in C++ with several arguments defined: argc (integer), argv (array of strings), and, in the case of ConsoleMethod, object (SimObject *).
line 233 engineoverview.txt
#2
05/19/2002 (4:22 pm)
Nope still doesn't work :(
#3
05/19/2002 (4:24 pm)
?
umm ok so why not?
what does it say when you run the function?
(the console error)
if Nothing is said.. then it prolly Is running :)

if it is not giving console error pop in a ,
Con::printf("or something");
#4
05/19/2002 (4:28 pm)
(0): Unknown Command gearShiftUp
#5
05/19/2002 (4:32 pm)
ConsoleMethod(ClassName, ConsoneFunctionName, ReturnType, 2, 2, "help text")
{
ClassName * bla = static_cast( object );
bla->ClassPublicFunctionCall();
}

2,2 to get object.
3,3 to pass in 1 arg
3,3 to pass in 2 args.....
#6
05/19/2002 (4:36 pm)
umm .. you Are typing
myObjectID.gearShiftUp();
into the console?
#7
05/19/2002 (4:40 pm)
%player = new muscleCar() {
dataBlock = DefaultCar;
client = %this;
};

That's the code I am using (like racing mod).

Then in console i am typing

DefaultCar.gearShiftUp();
#8
05/19/2002 (4:43 pm)
hmm I dont know i've never tried to access object's like that .. does it work?

you should open the editor..
and find the number on your object..
use the number

1379.gearShiftUp();

like that.

then you can see what to do.

Edit:
Besides you are trying to use the DataBlock to call that function when you defined it for the class no?

P.S. if it was working I think you would have shifted Every DefaultCar up a gear :)
#9
05/19/2002 (4:48 pm)
Awesome, I did a dump() and the method shows up now.

Thanks guys :)

Is there a variable that has your player's id number?

like %clientid
#10
05/19/2002 (5:02 pm)
hmm not for the most part I dont think
..
use [object].getId(); to resolve id.

you can create a script variable anywhere you like to store or pass it I guess .. more research into this could prove a variable is available *shrug* :)

great you got it going!