-
Notifications
You must be signed in to change notification settings - Fork 1
/
advanced_example.lua
48 lines (44 loc) · 1.06 KB
/
advanced_example.lua
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
-- load module
luabt = require('luabt')
function create_timer_node(seconds)
local timer = nil
return function()
if timer == nil then
-- reset the timer
timer = os.clock() + seconds
end
-- has the timer expired?
if os.clock() > timer then
-- reset timer for next time
timer = nil
return false, true
else
return true
end
end
end
-- define a memory behavior tree
timer_root_node = {
type = "sequence*",
children = {
function()
print("waiting for one second...")
return false, true
end,
create_timer_node(1),
function()
print("waiting for three seconds...")
return false, true
end,
create_timer_node(3),
function()
print("waiting for two seconds...")
return false, true
end,
create_timer_node(2),
}
}
-- instantiate a behavior tree
timer_bt = luabt.create(timer_root_node)
-- tick the behavior tree until it has finished (running == false)
while timer_bt() do end