forked from tka-andrew/learning_BehaviourTreeCPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial02_nodes.cpp
More file actions
41 lines (35 loc) · 1.27 KB
/
Copy pathtutorial02_nodes.cpp
File metadata and controls
41 lines (35 loc) · 1.27 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
#include "tutorial02_nodes.h"
namespace T02DummyNodes
{
BT::NodeStatus SaySomething::tick()
{
BT::Optional<std::string> msg = getInput<std::string>("message");
// Check if optional is valid. If not, throw its error
if (!msg)
{
throw BT::RuntimeError("missing required input [message]: ",
msg.error());
}
// use the method value() to extract the valid message.
std::cout << "Robot says: " << msg.value() << std::endl;
return BT::NodeStatus::SUCCESS;
}
BT::NodeStatus SaySomethingSimple(BT::TreeNode &self)
{
BT::Optional<std::string> msg = self.getInput<std::string>("message");
// Check if optional is valid. If not, throw its error
if (!msg)
{
throw BT::RuntimeError("missing required input [message]: ", msg.error());
}
// use the method value() to extract the valid message.
std::cout << "Robot says: " << msg.value() << std::endl;
return BT::NodeStatus::SUCCESS;
}
BT::NodeStatus ThinkWhatToSay::tick()
{
// the output may change at each tick(). Here we keep it simple.
setOutput("text", "The answer is 42");
return BT::NodeStatus::SUCCESS;
}
}