Skip to content

Commit 9493f10

Browse files
committed
Return None if blackboard value doesn't exist.
1 parent 6188c21 commit 9493f10

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

python_examples/ex02_generic_data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def tick(self):
6464
@ports(inputs=["value"])
6565
class Print(SyncActionNode):
6666
def tick(self):
67-
print(self.get_input("value"))
67+
value = self.get_input("value")
68+
if value is not None:
69+
print(value)
6870
return NodeStatus.SUCCESS
6971

7072

python_examples/ex03_stateful_nodes.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
2424
<BehaviorTree ID="MainTree">
2525
<Sequence>
26-
<!-- Initialize the interpolated position -->
27-
<SetBlackboard output_key="interpolated" value="None" />
28-
2926
<!-- Interpolate from the initial position to the final one printing
3027
at each step. -->
3128
<ReactiveSequence name="root">
@@ -63,7 +60,9 @@ def on_halted(self):
6360
@ports(inputs=["value"])
6461
class Print(SyncActionNode):
6562
def tick(self):
66-
print(self.get_input("value"))
63+
value = self.get_input("value")
64+
if value is not None:
65+
print(value)
6766
return NodeStatus.SUCCESS
6867

6968

src/python_bindings.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ class Py_StatefulActionNode final : public StatefulActionNode
5858
py::object Py_getInput(const TreeNode& node, const std::string& name)
5959
{
6060
py::object obj;
61-
node.getInput(name, obj);
61+
if (!node.getInput(name, obj).has_value())
62+
{
63+
return py::none();
64+
}
6265
return obj;
6366
}
6467

0 commit comments

Comments
 (0)