C++ lambda with scheduler

C++ lambda with scheduler
0

It is very easy and convient for me to use lambdas and I had completly no problems with it except
schedulers. I somehow cannot get it working. Can someone post working code for scheduling function?
Something like:

this->schedule(schedule_selector([](float dt){/*something*/})); 

… but working

Node is using pointers to member function, that’s why your code does not work. Use scheduler if you wish to use lambdas:

auto scheduler = Director::getInstance()->getScheduler();
scheduler->schedule([](float dt)
{
    log("callback");
}, this, 1.0f, kRepeatForever, 0.0f, false, "myCallbackKey");

Hi,
sorry for reviving back the topic.

@KJS

Can you please tell me what do you mean by

Also, what is the “CallbackKey

thanxx :slight_smile:

when use scheduler with Director::getInstance()->getScheduler()

Director::getInstance()->getScheduler()->schedule([&](float dt){
    log("scheduled");
}, this, 0.1f, false, "schedulerKey"); // target(this) is required

or

this->schedule([&](float dt){
    log("scheduled");
}, 0.f, 0, 0.2f, "schedulerKey"); // no target specified

and "schedulerKey" is a key for unschedule("schedulerKey");

3 Likes

Doing the both is same thing. Isn’t it?

and

I mean does it matter from where I am putting my update function because ultimately I will get my results. Isn’t it?

Thanx :smile: