Add New C++ Variable
by John Eckhardt · in RTS Starter Kit · 11/04/2006 (10:51 pm) · 2 replies
Ok, so here's what I want to do. I need a function: setNextPos(point) to set a variable inside the game engine.
This is for a pathfinding system I'm working on, and here is what I have got so far.
1. %movingObject.setNextPos(%x SPC %y SPC %z); is called inside a script file.
2. Inside RTSUnit.h Class RTSUnit -- private: I declare the variable which should hold the point.
3. I declare the getter and setter for that variable inside RTSUnit.h too
4. We go over to RTSUnit.cc and add a new function
I copied the functions for setAimLocation, and just changed the variables so that I could make sure mine would work, and guess what, it doesn't. When the script file calls the function, I get a Unknown Command error.
I'm afraid I'm missing some mask bit thing which I haven't a clue about. Maybe it's because I need to declare a console method? If so, where would I do that?
Any ideas?
This is for a pathfinding system I'm working on, and here is what I have got so far.
1. %movingObject.setNextPos(%x SPC %y SPC %z); is called inside a script file.
2. Inside RTSUnit.h Class RTSUnit -- private: I declare the variable which should hold the point.
bool mAimLocationSet; // Has an aim location been set? Point3F mAimLocation; // Point to look at Point3F mNextPos; //This Line is added
3. I declare the getter and setter for that variable inside RTSUnit.h too
S32 getTeam() const { return mTeam; }
Point3F getNextPos() const { return mNextPos; } //added
void setNextPos(const Point3F &location); // also added4. We go over to RTSUnit.cc and add a new function
void RTSUnit::setNextPos( const Point3F &location )
{
mNextPos = location;
}I copied the functions for setAimLocation, and just changed the variables so that I could make sure mine would work, and guess what, it doesn't. When the script file calls the function, I get a Unknown Command error.
I'm afraid I'm missing some mask bit thing which I haven't a clue about. Maybe it's because I need to declare a console method? If so, where would I do that?
Any ideas?
#2
Ok, I correctly made two console methods to get and set the value of mNextPos, and I'm certain they worked.
Now the problem I ran into was that I'd set mNextPos when the pathfinding figured out where it should go to avoid the obstacle. That worked fine. Then, as soon as we did a processTick, it forgot the value.
So, I tried making a maskbit to transfer mNextPos to the server to try to remember it. But for some reason, mNextPos would only be 'remembered' half the time. I couldn't break down any situation that would cause it to remember or not to.
Where can I find a decent tutorial on adding a new member to a class (if that's what you call it?)
11/08/2006 (7:24 pm)
(btw, I got my pathfinding to work, but it's all in script. However, I'd still like to find what I'm missing here)Ok, I correctly made two console methods to get and set the value of mNextPos, and I'm certain they worked.
Now the problem I ran into was that I'd set mNextPos when the pathfinding figured out where it should go to avoid the obstacle. That worked fine. Then, as soon as we did a processTick, it forgot the value.
So, I tried making a maskbit to transfer mNextPos to the server to try to remember it. But for some reason, mNextPos would only be 'remembered' half the time. I couldn't break down any situation that would cause it to remember or not to.
Where can I find a decent tutorial on adding a new member to a class (if that's what you call it?)
Torque Owner Johnathan Moore
ConsoleMethod( RTSUnit, setNextPos, void, 3, 3, "( Point3F pos)" "???.") { object->mNextPos = dAtoi(argv[2]); }it should work :D