Skip to content

The Repeater decorator seems something wrong #29

@starherder

Description

@starherder
// The Repeater decorator repeats infinitely or to a limit until the child returns success.
class Repeater : public Decorator
{
public:
    Repeater(int limit = 0) : limit(limit) {}

    void initialize() override
    {
        counter = 0;
    }

#if 0 // this is old function, seems you forgot the status of child->tick()
    Status update() override
    {
        child->tick();
        if (limit > 0 && ++counter == limit) {
            return Status::Success;
        }
        
        return Status::Running;
    }
#else  // this is a new one
    Status update() override
    {
        auto status = child->tick();
        if (status == Status::Success)
        {
            if (limit > 0 && ++counter == limit) {
                return Status::Success;
            }
        }

        return Status::Running;
    }
#endif

protected:
    int limit;
    int counter = 0;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions