ConsoleMethods
by Ben Woodhead · in Torque Game Engine · 02/22/2004 (9:30 am) · 2 replies
Hello Everybody,
I tried searching for an answer and have read the docs but I am still confused as to how I am suppost to accomplish my task. Before I begin, I would like to mention that I am working on a document on how to create a board type of game using torque (I am on the document team for torque). It is partly inspired by the TicTacToes demo but using more scripting. For right now I am just using the TicTacToe demo to try to get confortable with ConsoleMethods.
Ok, on to the question. I am trying to use a consolemethod but I am not sure how to call it. Here is some code:
tttTSCtrl.cc
IMPLEMENT_CONOBJECT(tttTSCtrl);
// There are of course the needed methods but we can skip them.
// My hello world method.
void tttTSCtrl::helloWorld() {
Con::printf("Hahahahah, it works.");
}
// My console method call.
ConsoleMethod( tttTSCtrl, helloWorld, void, 1, 1, "Man, it doesn't take params." ) {
object->helloWorld();
}
// The gui was created with tttTSCrtl as the GUIControl
new GuiControl(TicTacToeGui) {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "0 0";
extent = "800 600";
minExtent = "8 2";
visible = "1";
new tttTSCtrl() {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "3 3";
extent = "762 596";
minExtent = "8 2";
visible = "1";
cameraZRot = "0";
forceFOV = "0";
};
// There are some other buttons.
};
So he is what I have tried so far. I opened the console:
helloWorld(); // Fairly safe to say that will not work.
tttTSCrtl.helloWorld(); // Also didn't work
%tttTSCrtl.helloWorld(); // Also didn't work
TicTacToeGui.helloWorld(); // Didn't work.
%TicTacToeGui.helloWorld(); // Didn't work.
So I went to the gui control part and added a name to the new tttTSCtrl
new tttTSCtrl(myCtrl)
and then I tried from the console again.
%myCtrl.helloWorld.
Can someone please tell me how I am suppost to make this work. There is a chance that one of the things I have tried was it and I made some other mistake at the same time.
Thank you very much for any help.
Ben
I tried searching for an answer and have read the docs but I am still confused as to how I am suppost to accomplish my task. Before I begin, I would like to mention that I am working on a document on how to create a board type of game using torque (I am on the document team for torque). It is partly inspired by the TicTacToes demo but using more scripting. For right now I am just using the TicTacToe demo to try to get confortable with ConsoleMethods.
Ok, on to the question. I am trying to use a consolemethod but I am not sure how to call it. Here is some code:
tttTSCtrl.cc
IMPLEMENT_CONOBJECT(tttTSCtrl);
// There are of course the needed methods but we can skip them.
// My hello world method.
void tttTSCtrl::helloWorld() {
Con::printf("Hahahahah, it works.");
}
// My console method call.
ConsoleMethod( tttTSCtrl, helloWorld, void, 1, 1, "Man, it doesn't take params." ) {
object->helloWorld();
}
// The gui was created with tttTSCrtl as the GUIControl
new GuiControl(TicTacToeGui) {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "0 0";
extent = "800 600";
minExtent = "8 2";
visible = "1";
new tttTSCtrl() {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "3 3";
extent = "762 596";
minExtent = "8 2";
visible = "1";
cameraZRot = "0";
forceFOV = "0";
};
// There are some other buttons.
};
So he is what I have tried so far. I opened the console:
helloWorld(); // Fairly safe to say that will not work.
tttTSCrtl.helloWorld(); // Also didn't work
%tttTSCrtl.helloWorld(); // Also didn't work
TicTacToeGui.helloWorld(); // Didn't work.
%TicTacToeGui.helloWorld(); // Didn't work.
So I went to the gui control part and added a name to the new tttTSCtrl
new tttTSCtrl(myCtrl)
and then I tried from the console again.
%myCtrl.helloWorld.
Can someone please tell me how I am suppost to make this work. There is a chance that one of the things I have tried was it and I made some other mistake at the same time.
Thank you very much for any help.
Ben
About the author
Torque 3D Owner Robert Blanchet Jr.
So a console function for this would look like:
ConsoleFunction(HelloWorld, void, 1, 1, "says Hello World") { Con::printf("Hello World"); }If you look closely we see this part:
The first is the return type (in this case void), the second is the number of minimum arguements the function will take, and the last is the number of maximum arguements the function will take. So in this case, my HelloWorld console function will return a string and take 1 arguement maximum. The arguement in this case is the function name itself, 'HelloWorld'.
Now that we are armed with this knowledge lets take a look at your ConsoleMethod and fix it.
wrong
// My console method call. ConsoleMethod( tttTSCtrl, helloWorld, void, 1, 1, "says Hello World" ) { object->helloWorld(); }right
// My console method call. ConsoleMethod( tttTSCtrl, helloWorld, void, 2, 2, "says Hello World" ) { object->helloWorld(); }What do you see differently? Like I said above to determine our arguement counts we should count the number of words we have to type in order to execute the function in the console or in script. In this case I need an object, thats the 'tttTSCtrl', so thats one. I then need the function itself, thats the 'helloWorld', so thats two. My method takes no arguements itself so we are left with two total.
To use this in script we first need a tttTSCtrl object created. To do this I'll name the tttTSCtrl object.
// The gui was created with tttTSCrtl as the GUIControl new GuiControl(TicTacToeGui) { profile = "GuiDefaultProfile"; horizSizing = "right"; vertSizing = "bottom"; position = "0 0"; extent = "800 600"; minExtent = "8 2"; visible = "1"; new tttTSCtrl(tttTSObject) { profile = "GuiDefaultProfile"; horizSizing = "right"; vertSizing = "bottom"; position = "3 3"; extent = "762 596"; minExtent = "8 2"; visible = "1"; cameraZRot = "0"; forceFOV = "0"; }; }; // this will print 'Hello World' tttTSObject.helloWorld();