Page 1 of 1

subscribeEvent function parameter taking more than one arg?

Posted: Thu Oct 27, 2011 16:53
by pighead10

Code: Select all

guiRoot->getChild("Root/AddMiner")->subscribeEvent(CEGUI::PushButton::EventClicked,CEGUI::Event::Subscriber(&GameState::addMiner,this));


I want GameState::addMiner to have an additional argument passed to it, as well as the necessary const CEGUI::EventArgs& one. Is there any easy way I can do this with CEGUI instead of making some other hacky fix?

Re: subscribeEvent function parameter taking more than one a

Posted: Thu Oct 27, 2011 17:27
by Kulik
Use boost::bind, CEGUI's subscriber event system is compatible with it.

PS: We would appreciate a wiki article about this, I am pretty sure there is none. :)

Re: subscribeEvent function parameter taking more than one a

Posted: Thu Oct 27, 2011 20:36
by pighead10
I've never used the boost library myself. Is there an easy way of explaining what it does? I'm relatively new to C++ and am not familiar with stl bind functions either.

Re: subscribeEvent function parameter taking more than one a

Posted: Thu Oct 27, 2011 22:45
by Kulik
Sorry but I will pull the RTFM acronym :-) boost.org has good documentation, use it. It's no rocket science, no reason to be scared of it. I also think there aren't many easier ways to bind parameters to functions.

Re: subscribeEvent function parameter taking more than one a

Posted: Fri Oct 28, 2011 00:49
by Jamarr
You could just define an object that stores the parameters you need as members, and then use instances of those objects as event handlers. When an instance is called to handle an event, have it call your addMiner function passing the relevant members. You can find the basics of this here. My understanding of boost::bind is basically that it generalizes and simplifies this process for you.

p.s. I know I should probably be more familiar with and taking advantage of boost by now lol :oops: