schedule_selector with parameters

Hi,

I want to call a function with schedule. The problem is that my function takes certain arguments but I dont know how to pass them in the scheduler. One option which I know is to declare parameters as members but I dont want to take that route. Does anybody have the solution for this?

I got following solution from http://discuss.cocos2d-x.org/t/it-is-possible-to-pass-an-argument-with-schedule-selector/1426/3:

this->runAction(CCSequence::actions(CCDelayTime::actionWithDuration(_tiemToDelay),CCCallFunc::actionWithTarget(this,callfunc_selector(xxx::functionYouWant),NULL));

But this is in older version of Cocos2d-x. Can anybody let me know how to do it in Cocos2d-x V3?

Thanks-in-advance.

Use lambdas instead and capture the variables you need:

//Create delay time action
auto delayTimeAction = DelayTime::create(delay);

//Create callfunc with lambda. Lambda must be of type std::function<void(void)> but we can capture variables we need
std::string string = "CallFunc executed!";
auto callfuncAction = CallFunc::create([string]() {
    CCLOG("%s", string.c_str());
});

this->runAction(Sequence::create(delayTimeAction, callfuncAction, nullptr));

Learn more about lambdas here:
http://www.drdobbs.com/cpp/lambdas-in-c11/240168241
http://en.cppreference.com/w/cpp/language/lambda