jica.monsanto.ph Posted March 23, 2012 Posted March 23, 2012 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
unclebob Posted March 23, 2012 Posted March 23, 2012 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); } }; 1
mandee.cabato.ph Posted March 23, 2012 Posted March 23, 2012 Hi, is this in the documentation? We're all newbies in the team and haven't quite figured our way around the documents. :-)
unclebob Posted March 23, 2012 Posted March 23, 2012 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. :)
manguste Posted April 27, 2012 Posted April 27, 2012 I've added info on callbacks in the inherited classes (Bob's examples) into docs :)
Recommended Posts