Game Development Community

ai setMoveDestination question? bug?

by Matt · in Torque Game Engine · 03/03/2002 (10:17 pm) · 3 replies

I just purchased Torque a couple days ago and am just playing around with the bots for now. I have a couple questions in the aiPlayer.cc file.

This is code from the aiplayer.cc file.

ConsoleMethod( AIConnection, setMoveDestination, void, 3, 3, "ai.setMoveDestination( x y z );" ) {
AIPlayer *ai = static_cast( object );
Point3F v( 0.0f, 0.0f, 0.0f );
dSscanf( argv[2], "%f %f", &v.x, &v.y );

ai->setMoveDestination( v );
}

When I try to run the console command such as $ai.setMoveDestination(1.0,1.0,1.0); it tells me the number of arguments are wrong. But $ai.setMoveDestination(1.0); does work, but only changes the x coordinate.

For one thing, I thought the 3, 3 in the Console Method meant both the minumum number of parameters required was 2, but it appears the number required is only one. If I change the function to ConsoleMethod(.... ,4 ,4 ...) then it will accept an X and Y coordinate, but doesn't apply the Y coordinate either.

So I came up with a solution and would like some feedback as if this is the right thing to do, or am I just missing something all together?

I changed the function to the following:

ConsoleMethod( AIConnection, setMoveDestination, void, 4, 4, "ai.setMoveDestination( x y );" ) {
AIPlayer *ai = static_cast( object );
Point3F v( 0.0f, 0.0f, 0.0f );
dSscanf( argv[2], "%f", &v.x);
dSscanf( argv[3], "%f", &v.y);
ai->setMoveDestination( v );
}



Thanks,

Matt

About the author

Recent Threads


#1
03/03/2002 (10:56 pm)
You simply have to put the coordinates in quotes, like that:
$myBot01.setMoveDestination("-224.153 -166.305 214.662"); 
$myBot01.move();

You can also play around with my basic tutorial:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2215

Have fun!
#2
03/03/2002 (11:40 pm)
Since there's no "set" variable type in the script language, things like a 3d point in C++ must be represented wiht a string (then converted once it reaches C++)

In this case, you must give it a string in the format of:

"float float float". So you DO only give it one value, but C++ will end up converting it to type point3f which has the member variables .x .y and .z to help organize the 3d coordinate for easier processing.

I made the same mistake :P Just messing around with script/c++ function handling really is a good way to understand the way things are converted between the two.

All variables sent from script to c++ are in string format (even integers) so you must use the string to [variable type you want] conversions. For an example look at any c++ function that accepts a variable from the script.
#3
03/04/2002 (7:38 am)
I could have swore I tried it with the quotes as one of the first things I did. Guess I was up too late last night. Thanks for the responses.

-Matt