Add more built-in node types
This commit is contained in:
parent
6dfeb4d831
commit
4422642458
64
init.lua
64
init.lua
@ -118,7 +118,31 @@ Tactree.Leaf 'Sequence'
|
||||
end
|
||||
}
|
||||
|
||||
Tactree.Leaf 'Repeat'
|
||||
Tactree.Leaf 'Selector'
|
||||
{
|
||||
start = function(node)
|
||||
node:private().current_child = 1
|
||||
node.children[node:private().current_child]:start()
|
||||
end,
|
||||
tick = function(node)
|
||||
local result = node.children[node:private().current_child]:update()
|
||||
|
||||
if type(result) == 'boolean' then
|
||||
if not result then
|
||||
if node:private().current_child == #node.children then
|
||||
return false
|
||||
else
|
||||
node:private().current_child = node:private().current_child + 1
|
||||
node.children[node:private().current_child]:start()
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
Tactree.Leaf 'RepeatUntilFail'
|
||||
{
|
||||
start = function(node)
|
||||
node.children[1]:start()
|
||||
@ -127,13 +151,45 @@ Tactree.Leaf 'Repeat'
|
||||
local result = node.children[1]:update()
|
||||
|
||||
if type(result) == 'boolean' then
|
||||
if not result then return false end
|
||||
|
||||
node.children[1]:start()
|
||||
if not result then
|
||||
return true
|
||||
else
|
||||
node.children[1]:start()
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
Tactree.Leaf 'RepeatUntilPass'
|
||||
{
|
||||
start = function(node)
|
||||
node.children[1]:start()
|
||||
end,
|
||||
tick = function(node)
|
||||
local result = node.children[1]:update()
|
||||
|
||||
if type(result) == 'boolean' then
|
||||
if result then
|
||||
return true
|
||||
else
|
||||
node.children[1]:start()
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
Tactree.Leaf 'RepeatForever'
|
||||
{
|
||||
start = function(node)
|
||||
node.children[1]:start()
|
||||
end,
|
||||
tick = function(node)
|
||||
local result = node.children[1]:update()
|
||||
|
||||
if type(result) == 'boolean' then node.children[1]:start() end
|
||||
end
|
||||
}
|
||||
|
||||
--[[
|
||||
Example usage
|
||||
-------------
|
||||
|
Loading…
Reference in New Issue
Block a user