Add more built-in node types

This commit is contained in:
Shylie 2024-06-27 15:31:21 -04:00
parent 6dfeb4d831
commit 4422642458

View File

@ -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
-------------