Adding a new function to engine - Help needed
by Richard Marrevee · in Torque 3D Professional · 05/10/2012 (1:21 pm) · 8 replies
In the source code I created a new function called findNavPath to create a path and add some markers to this path, then returning the ID of this path to script. I use the DefineEngineFunction(...) to expose this new function to script. Now the problem is that when I call this new function in the console (to test it) I get:
<input> (0): unable to find function findNavPath
I looked at the official documents regarding this, but I can't see any difference between the examples and my new function, so the question is what am I doing wrong or did I miss something?
So any help is appreciated.
Thanks
<input> (0): unable to find function findNavPath
I looked at the official documents regarding this, but I can't see any difference between the examples and my new function, so the question is what am I doing wrong or did I miss something?
So any help is appreciated.
Thanks
About the author
Started programming in 1984 on an Oric, when time progressed switched to MSX, Amiga and finally the Windows PC with T3D. Now developing an epic fantasy game: The Master's Eye. Creator of the DoorClass pack and VolumetricFog pack @ richardsgamestudio.com
#2
05/10/2012 (1:58 pm)
As requested my new function#include "platform/platform.h"
#include "scene/simPath.h"
#include "T3D/navigation/NavMesh.h"
#include "console/engineAPI.h"
//S32 findNavPath(NavMesh *nm,Point3D start, Point3D end, int mode);
DefineEngineFunction( findNavPath, S32, (NavMesh *nm,Point3D start, Point3D end, int mode),,
"@brief Gets the navigation path between two points.nn"
"@param nm NavMesh.n"
"@param start The position to start the path from.n"
"@param end The position to end the path at.n")
{
if (nm)
{
Sample* sample=nm->sample;
if(sample)
{
PathMode pm;
if (mode == 0)
pm = PATHMODE_STRAIGHT;
else if (mode == 1)
pm = PATHMODE_FOLLOW;
else if (mode == 2)
pm = PATHMODE_SLICED;
else
pm = PATHMODE_STRAIGHT;
float spos[3];
float epos[3];
spos[0] = start.x;
spos[1] = start.z;
spos[2] = -start.y;
epos[0] = end.x;
epos[1] = end.z;
epos[2] = -end.y;
sample->setPath(new NavMeshPath);
sample->handlePath(spos, epos, pm);
float* path = NULL;
int numPoints = 0;
if(pm == PATHMODE_FOLLOW)
{
numPoints = sample->getPath()->getNumSmoothPath();
path = sample->getPath()->getSmoothPath();
}
else if(pm == PATHMODE_STRAIGHT || pm == PATHMODE_SLICED)
{
numPoints = sample->getPath()->getNumStraightPath();
path = sample->getPath()->getStraightPath();
}
Path* NavPath=new Path();
for(int i = 0; i < numPoints; ++i)
{
Marker* mk=new Marker();
mk->mSeqNum=i;
Point3D pos;
pos.x=path[i*3];
pos.y=-path[i*3+2];
pos.z=path[i*3+1];
mk->setPosition(pos);
NavPath->addObject(mk);
}
}
return NavPath->getID();
}
return -1;
}
#3
I then created the files in the source dir, and replaced the ones in my project by adding existing item - then they turn up...
05/10/2012 (3:06 pm)
I came across something similar once... via visual studio I created a new file, compiled etc...but nothing...I then created the files in the source dir, and replaced the ones in my project by adding existing item - then they turn up...
#4
vs
Normally I wouldn't point it out, but it is the only difference that I see....
05/17/2012 (9:31 am)
The only difference I see is the space before the closing parenthesis -DefineEngineFunction( findNavPath, S32, (NavMesh *nm,Point3D start, Point3D end, int mode),, "@brief Gets the navigation path between two points.nn" "@param nm NavMesh.n" "@param start The position to start the path from.n" "@param end The position to end the path at.n")
vs
DefineConsoleFunction( quitWithErrorMessage, void, ( const char* message ),, "Display an error message box showing the given @a message and then shut down the engine and exit its process.\n" "This function cleanly uninitialized the engine and then exits back to the system with a process " "exit status indicating an error.\n\n" "@param message The message to log to the console and show in an error message box.\n\n" "@see quit\n\n" "@ingroup Platform" )
Normally I wouldn't point it out, but it is the only difference that I see....
#5
05/17/2012 (10:44 am)
Not being patronising, but you're not compiling your changes into a debug build then running a release build are you? I've done it.
#6
05/17/2012 (11:41 am)
Hah! Me too! My favorite SNAFU....
#7
I have been doing all of my function exports using the old functions from the console namespace: Con::addCommand. I looked the the DefineConsoleFunction code and in the past I had used the older console function macros.
Is the Con::addCommand part of the DefineConsoleFunction macros?
Is that going to be deprecated in the future?
Mainly I want to know as right now I am relying on the Con::addCommand.
05/17/2012 (9:37 pm)
@Richard,I have been doing all of my function exports using the old functions from the console namespace: Con::addCommand. I looked the the DefineConsoleFunction code and in the past I had used the older console function macros.
Is the Con::addCommand part of the DefineConsoleFunction macros?
Is that going to be deprecated in the future?
Mainly I want to know as right now I am relying on the Con::addCommand.
#8
@Guy: It's a mistake easily made, but not this time (unfortunately).
Because this new function is supposed to work with AI I transfered it to the AI class and used DefineEngineMethod and all works very well.
Though it´s strange it didn´t work with DefineEngineFunction.
05/18/2012 (2:08 am)
Thanks for the advice guys. I wil try them and see what happens.@Guy: It's a mistake easily made, but not this time (unfortunately).
Because this new function is supposed to work with AI I transfered it to the AI class and used DefineEngineMethod and all works very well.
Though it´s strange it didn´t work with DefineEngineFunction.
Associate Chris Haigler
Jester Dance