forked from BehaviorTree/BehaviorTree.CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht09_scripting.cpp
More file actions
58 lines (47 loc) · 1.29 KB
/
t09_scripting.cpp
File metadata and controls
58 lines (47 loc) · 1.29 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
47
48
49
50
51
52
53
54
55
56
57
58
#include "behaviortree_cpp/bt_factory.h"
#include "dummy_nodes.h"
using namespace BT;
// clang-format off
static const char* xml_text = R"(
<root BTCPP_format="4">
<BehaviorTree>
<Sequence>
<Script code=" msg:='hello world' " />
<Script code=" A:=THE_ANSWER; B:=3.14; color:=RED " />
<Precondition if="A>-B && color != BLUE" else="FAILURE">
<Sequence>
<SaySomething message="{A}"/>
<SaySomething message="{B}"/>
<SaySomething message="{msg}"/>
<SaySomething message="{color}"/>
</Sequence>
</Precondition>
</Sequence>
</BehaviorTree>
</root>
)";
// clang-format on
int main()
{
BehaviorTreeFactory factory;
factory.registerNodeType<DummyNodes::SaySomething>("SaySomething");
enum Color
{
RED = 1,
BLUE = 2,
GREEN = 3
};
// We can add these enums to the scripting language
factory.registerScriptingEnums<Color>();
// Or we can do it manually
factory.registerScriptingEnum("THE_ANSWER", 42);
auto tree = factory.createTreeFromText(xml_text);
tree.tickWhileRunning();
return 0;
}
/* Expected output:
Robot says: 42.000000
Robot says: 3.140000
Robot says: hello world
Robot says: 1.000000
*/