Jump to content

[SOLVED] Set WorldTrigger callbacks within user class instance


photo

Recommended Posts

Hi!

 

I have a class that 'inherits' from WorldTrigger. When I call setEnterCallback() inside the class, this error shows:

WorldTriggerCallback::run(): can't find "on_enter" callback function

where "on_enter" is a method inside my WorldTrigger child class.

 

I tried calling setEnterCallback() in the world script. It worked but the callback function is inside the world script. I'd like to know if there's a way to set the callback to be an instance method and not a world script method since I will be managing lots of trigger instances with callbacks.

 

Thanks!

 

P.S. I'd like to apply this to Widgets and BodyRigids too

Link to comment

Hi,

 

Yes, you can put callbacks inside classes. Main idea is to pass reference to 'this' as additional argument. Here is an example for WorldTrigger:

 

class MyTrigger : WorldTrigger {
 private:

   /*
    */
   void on_enter(Node node,MyTrigger trigger) {
     log.message("on_enter: %s %s\n",typeinfo(node),typeinfo(trigger));
   }

   /*
    */
   void on_leave(Node node,MyTrigger trigger) {
     log.message("on_leave: %s %s\n",typeinfo(node),typeinfo(trigger));
   }

 public:

   MyTrigger(vec3 sizes) {
     extern = new WorldTrigger(sizes);
     extern.setEnterCallback("::MyTrigger::on_enter",this);
     extern.setLeaveCallback("::MyTrigger::on_leave",this);
   }
};

 

And for widgets:

 

class MyButton : WidgetButton {
 private:

   /*
    */
   void on_click(MyButton button) {
     log.message("on_click: %s\n",typeinfo(button));
   }

 public:

   MyButton(Gui gui) {
     extern = new WidgetButton(gui);
     extern.setCallback(GUI_CLICKED,"::MyButton::on_click",this);
   }
};

  • Like 1
Link to comment

I didn't quite get your question.

 

But our docs have information about 'inheritance' from extern classes and about WorldTrigger callbacks.

 

About inheritance: https://developer.un.../language/class (see 'Inheritance from Base Engine and Extern C++ Classes' section)

About WorldTrigger callbacks: https://developer.un...ss.worldtrigger (see 'WorldTrigger::setLeaveCallback' and 'WorldTrigger::setEnterCallback' sections)

 

Also, you can see this topic about inheritance details: https://developer.un...__fromsearch__1

 

Hope I answered your question. :)

Link to comment
  • 1 month later...
×
×
  • Create New...