Game Development Community

Question about the Script command "Parent::" Please help !

by Vince Gee · in Torque 3D Professional · 02/06/2012 (9:20 am) · 2 replies

Ok,

I'm talking about the torquescript command Parent::function()

But I need to be able to do it from the c++.

So I have a sim Object handle, I want to call a function in the parents namespace.

I would really appreciate it if someone could post some code on how to do this, I've been screwing around with it for a while with no luck for days.

Vince

#1
02/06/2012 (11:33 pm)
Here is my guess:
// use whatever function you want or string representation
char * fname = "func";
// make sure it has a parent
if(object->parent){
  // make sure the function exists as there is no error returned I think
  if(object->parent->isMethod(fname)){
    // call the function
    // where: char* argv[] = {"func", "", "2"};
    // first two args are required, last one is the first arg.
    // You can find this documented on line 574 of console.h
    char* argv[] = {fname, "", "2"};
    char *ret = Con::execute(object->parent, len(argv), argv);
  }
}
That should do it!
#2
02/07/2012 (5:03 am)
Thanks Frank!