-
Notifications
You must be signed in to change notification settings - Fork 825
Expand file tree
/
Copy pathex01_sample.py
More file actions
46 lines (33 loc) · 1.03 KB
/
ex01_sample.py
File metadata and controls
46 lines (33 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
"""
Demo adapted from [btcpp_sample](https://github.com/BehaviorTree/btcpp_sample).
"""
from btpy import BehaviorTreeFactory, SyncActionNode, NodeStatus, ports
xml_text = """
<root BTCPP_format="4" >
<BehaviorTree ID="MainTree">
<Sequence name="root">
<AlwaysSuccess/>
<SaySomething message="this works too" />
<ThinkWhatToSay text="{the_answer}"/>
<SaySomething message="{the_answer}" />
</Sequence>
</BehaviorTree>
</root>
"""
@ports(inputs=["message"])
class SaySomething(SyncActionNode):
def tick(self):
msg = self.get_input("message")
print(msg)
return NodeStatus.SUCCESS
@ports(outputs=["text"])
class ThinkWhatToSay(SyncActionNode):
def tick(self):
self.set_output("text", "The answer is 42")
return NodeStatus.SUCCESS
factory = BehaviorTreeFactory()
factory.register(SaySomething)
factory.register(ThinkWhatToSay)
tree = factory.create_tree_from_text(xml_text)
tree.tick_while_running()