Skip to content

Commit 74c7dd7

Browse files
authored
WhileDoElseNode can have 2 or 3 children (#625)
1 parent ba1d475 commit 74c7dd7

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/controls/while_do_else_node.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ NodeStatus WhileDoElseNode::tick()
2929
{
3030
const size_t children_count = children_nodes_.size();
3131

32-
if (children_count != 3)
32+
if (children_count != 2 && children_count != 3)
3333
{
34-
throw std::logic_error("WhileDoElse must have 3 children");
34+
throw std::logic_error("WhileDoElseNode must have either 2 or 3 children");
3535
}
3636

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

4848
if (condition_status == NodeStatus::SUCCESS)
4949
{
50-
haltChild(2);
50+
if (children_count == 3)
51+
{
52+
haltChild(2);
53+
}
5154
status = children_nodes_[1]->executeTick();
5255
}
5356
else if (condition_status == NodeStatus::FAILURE)
5457
{
55-
haltChild(1);
56-
status = children_nodes_[2]->executeTick();
58+
if (children_count == 3)
59+
{
60+
haltChild(1);
61+
status = children_nodes_[2]->executeTick();
62+
}
63+
else if (children_count == 2)
64+
{
65+
status = NodeStatus::FAILURE;
66+
}
5767
}
5868

5969
if (status == NodeStatus::RUNNING)

0 commit comments

Comments
 (0)