Skip to content

Commit

Permalink
WhileDoElseNode can have 2 or 3 children (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aglargil authored Aug 8, 2023
1 parent ba1d475 commit 74c7dd7
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/controls/while_do_else_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ NodeStatus WhileDoElseNode::tick()
{
const size_t children_count = children_nodes_.size();

if (children_count != 3)
if (children_count != 2 && children_count != 3)
{
throw std::logic_error("WhileDoElse must have 3 children");
throw std::logic_error("WhileDoElseNode must have either 2 or 3 children");
}

setStatus(NodeStatus::RUNNING);
Expand All @@ -47,13 +47,23 @@ NodeStatus WhileDoElseNode::tick()

if (condition_status == NodeStatus::SUCCESS)
{
haltChild(2);
if (children_count == 3)
{
haltChild(2);
}
status = children_nodes_[1]->executeTick();
}
else if (condition_status == NodeStatus::FAILURE)
{
haltChild(1);
status = children_nodes_[2]->executeTick();
if (children_count == 3)
{
haltChild(1);
status = children_nodes_[2]->executeTick();
}
else if (children_count == 2)
{
status = NodeStatus::FAILURE;
}
}

if (status == NodeStatus::RUNNING)
Expand Down

0 comments on commit 74c7dd7

Please sign in to comment.