Calling a lambda func inside scheduler not working?

Hello,
here is my code

#include "HelloWorldScene.h"

USING_NS_CC;


Scene* HelloWorld::createScene()
{
    auto scene = HelloWorld::create();
    return scene;
}


void HelloWorld::myMethodA(int value)
{
	CCLOG("%i", value);
}


void HelloWorld::myMethodB()
{
	CCLOG("Helloooo");
}


bool HelloWorld::init()
{
    if ( !Scene::init() )
        return false;
	
	auto someLambdaFunc = CallFunc::create( [=] () { 
         CCLOG("Byeeee");	
    }
    );

    // Loading section 2
		auto scheduler = Director::getInstance()->getScheduler();
		scheduler->schedule([=] (float dt) {
			myMethodA(5);
			myMethodB();
			someLambdaFunc;
		}, this, 0, 0, 5, false, "someName"); 

    return true;
}

The result is ok for all methods execpt the lambda. So the outup prints 5 from myMethodA() and "Hellooo"
from myMethodB, but not "Byeee" is printed out, which is what someLambdaFunc does.
What Am I missing here?

thanks,
R


Lambda function should be call someLambdaFunc();

No, that doesn’t compile. I tried that before posting. By doind someLambdaFunc() , I ger the error : “expression preciding parenthesis of apparent call must have (pointer-to) function type”.

This is not a lambda expression, but rather a Cocos2d-x Action.

You probably meant to do this:

auto someLambdaFunc = [=] () -> void { 
         CCLOG("Byeeee");	
    };

More info here.

CallFunc is used if you want to run some custom code in an action, such as via the Node::runAction() method, and has nothing to do with lambdas besides accepting one as a parameter.

1 Like

Ahh yes, that makes much more sense.
Thank you