OnRemove callback help
by Bryce · in Torque Game Engine · 11/22/2009 (6:51 pm) · 6 replies
Hi everyone!
I'm trying get a console callback to work with a C++ object's onRemove function:
How would one go about exposing this to script? What I mean is having an AIPathNode::OnRemove(%this,%obj) script function called. I've been playing around with Con::executef(), but I'm unfamiliar with the syntax.
Help is appreciated!
I'm trying get a console callback to work with a C++ object's onRemove function:
void AIPathNode::onRemove()
{
Parent::onRemove();
}How would one go about exposing this to script? What I mean is having an AIPathNode::OnRemove(%this,%obj) script function called. I've been playing around with Con::executef(), but I'm unfamiliar with the syntax.
Help is appreciated!
#2
Con::getIntArg(int), getFloatArg(float), and getArgBuffer(size) which gives you a char* of (size) that you can then fill with dSprintf or whatever.
11/22/2009 (7:31 pm)
Quote:There are other Con::getSomeSortOfArg methods for different data types.
Con::getIntArg(int), getFloatArg(float), and getArgBuffer(size) which gives you a char* of (size) that you can then fill with dSprintf or whatever.
#3
But the console says that ProperlyRemoveNode is an 'unknown command'. It doesn't recognize it as a function (yes, I'm sure I defined it properly). Thoughts?
11/22/2009 (8:16 pm)
I triedCon::executef(2,"ProperlyRemoveNode",scriptThis());
But the console says that ProperlyRemoveNode is an 'unknown command'. It doesn't recognize it as a function (yes, I'm sure I defined it properly). Thoughts?
#4
Seriously, where and how did you define it? Because that should work.
Aside: You were originally talking about exposing an onRemove event to script. I'm curious how that mutated into ProperlyRemoveNode? It seems a curious choice of words. Can I remove a node improperly?
11/22/2009 (9:45 pm)
Thought: You didn't define it properly. :-oSeriously, where and how did you define it? Because that should work.
Aside: You were originally talking about exposing an onRemove event to script. I'm curious how that mutated into ProperlyRemoveNode? It seems a curious choice of words. Can I remove a node improperly?
#5
I'm using Gabriel Notman's pathfinding resource, which requires you to call AIPaths.removeObjectSafe(%node) in the console before actually deleting the node to avoid screwing up the adjacency data. I was hoping to get it to do the safe remove procedure upon being deleted, but that crashes the engine...
Plan B. I'll see what I can do with the world editor's selection delete function to check for path nodes, and properly remove them before deletion. Thanks for the help!
11/23/2009 (12:31 am)
I'm smart. I edited the right file, but it was one of my backups from five months ago :PI'm using Gabriel Notman's pathfinding resource, which requires you to call AIPaths.removeObjectSafe(%node) in the console before actually deleting the node to avoid screwing up the adjacency data. I was hoping to get it to do the safe remove procedure upon being deleted, but that crashes the engine...
Plan B. I'll see what I can do with the world editor's selection delete function to check for path nodes, and properly remove them before deletion. Thanks for the help!
#6
11/23/2009 (3:42 am)
Quote:I was hoping to get it to do the safe remove procedure upon being deleted, but that crashes the engine...Any more info about that? Seems like a worthwhile pursuit to have path nodes 'get their affairs in order' before they go, so to speak - as opposed to having to get their affairs in order for them. Seems like quite a roundabout route to go through the world editor, where your changes will apply to all deleted objects.
Torque Owner Daniel Buckmaster
T3D Steering Committee
Can someone clear this up - wouldn't it be easier to just call one scriptOnRemove/Add/NewDatablock in GameBase and for the derived classes not to have to worry about it?
Oh - and welcome to the code side ;P
Oh again - Con::executef can be called one of two ways - on an object, or just as a function.
That's like doing %object.doYourThing(%otherObject); and you'd have to define doYourThing as
The '3' means there are three arguments being passed, which is confusing, since there are only two 'arguments' that go to the script function (the object and otherObject), but Con::executef counts the function name as an 'argument'.
That will just call the function 'myFunction', which should be defined as
Note again that I specified 2 arguments even though the function only receives one.
I'm pretty sure all the arguments you pass have to be of const char* type, so if you have an integer, you can either use dSprintf to write it into a string buffer, or use Con::getIntArg(myInt). There are other Con::getSomeSortOfArg methods for different data types.