Repeat action, what am I doing wrong?

consider this code

runAction(Repeat::create(CallFunc::create([this]() {
    CCLOG("hey");
}), 10));

isn’t this supposed to write out “hey” 10 times? it never stops…

It sounds like what is happening is that you have an update() method that is running each frame and you are getting hey 10 times each frame.

I have an engineer looking at this. I tried a few things to test what I think the results should be.

One of the engineers told me that it doesn’t work because CallFunc is not an Action

/** Creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30).
     *
     * @param action The action needs to repeat.
     * @param times The repeat times.
     * @return An autoreleased Repeat object.
     */
    static Repeat* create(FiniteTimeAction *action, unsigned int times);

Hmm ok. I didn’t get an error because the grandparent of CallFunc is the Action class:
CallFunc -> ActionInstant -> FiniteTimeAction -> Action

I usually use the schedule method for these purposes:

void Node::schedule(const std::function<void(float)>& callback, float interval, unsigned int repeat, float delay, 
const std::string &key)

But this time I thought I’d try the Repeat-action… I’ll have to look up how to actually use that later, hehe. Thanks for the help, though!

How could that be? CallFunc inherits from ActionInstant which is a subclass of FiniteTimeAction.
The logics in Repeat::update are quite messy, I suggest to use Scheduler instead.

Let me ask Engineering to take a look at this again

Adding _total++; after the if block will solve this question, it’s a bug for Repeat ActionInstant

Added a Issues: https://github.com/cocos2d/cocos2d-x/issues/18744