How do you add onAdd to Path in TGE
by Katrina Rose · in Torque Game Engine · 09/29/2004 (4:22 am) · 5 replies
Hi,
I would like to add the onAdd callback to path, but I don't know what I need to add to the engine. I looked into this before, but I could not figure it out. I need to make my bots automatically spawn to each path that I make, and if I have the bot spawn in the onAdd method of the path then I will not have to do anything else. As it is right now I create a botSpawn item close to the path and I have a method that uses a hard coded path count to spawn the bots to the correct path. Any help would be greatly appreciated.
Marrion
I would like to add the onAdd callback to path, but I don't know what I need to add to the engine. I looked into this before, but I could not figure it out. I need to make my bots automatically spawn to each path that I make, and if I have the bot spawn in the onAdd method of the path then I will not have to do anything else. As it is right now I create a botSpawn item close to the path and I have a method that uses a hard coded path count to spawn the bots to the correct path. Any help would be greatly appreciated.
Marrion
About the author
#2
The first command though.. what is it that you're trying to do? If it's a shapebase object, wouldn't just this fit?
Probably to no help, but I haven't seen the first command you mentioned.
Good luck.
09/30/2004 (3:26 am)
I'm no programmer, but to me it looks like the commands you're looking for do not exist.The first command though.. what is it that you're trying to do? If it's a shapebase object, wouldn't just this fit?
ShapeBase* control = conn->getControlObject(); control->getType();
Probably to no help, but I haven't seen the first command you mentioned.
Good luck.
#3
09/30/2004 (3:30 am)
I am trying to add the onAdd function to paths. I want to know when each path is added. When a player is added the onAdd function is called and you can mount objects and add inventory to the player as the are added to the scene. Paths do not have this ability, so I am trying to add it.
#4
It's funny how some things work out. While I was integrating the lighting pack into TGE 1.3 I happened upon a code that shows how to use callbacks. I copied the code to notepad and continued with the lighting pack. After I had the lighting pack in and working, and our TGE 1.2 code merged back in I added the code to enable the call back. Everything is working like a charm now. Find this in your engine/SimPath.cc file:
and change it to this:
Then make:
Now everytime a path is added you can spawn a bot on that path automatically. Just add the spawn code in the Path::onAdd.
Marrion
09/30/2004 (10:02 am)
Hi Everyone,It's funny how some things work out. While I was integrating the lighting pack into TGE 1.3 I happened upon a code that shows how to use callbacks. I copied the code to notepad and continued with the lighting pack. After I had the lighting pack in and working, and our TGE 1.2 code merged back in I added the code to enable the call back. Everything is working like a charm now. Find this in your engine/SimPath.cc file:
bool Path::onAdd()
{
if(!Parent::onAdd())
return false;
return true;
}and change it to this:
bool Path::onAdd()
{
if(!Parent::onAdd())
return false;
Con::executef(this, 2, "onAdd", Con::getIntArg(getId()));
return true;
}Then make:
function Path::onAdd(%this, %obj)
{
echo("Path added");
}Now everytime a path is added you can spawn a bot on that path automatically. Just add the spawn code in the Path::onAdd.
Marrion
#5
09/30/2004 (10:22 am)
For some classes you can use scriptOnAdd();(I used it for tiggers), but for other you need to call it like you did.
Katrina Rose
Default Studio Name
if (isServerObject()) scriptOnAdd();But I am getting the following error:
What am I missing? Please help.
Marrion