diff --git a/init.lua b/init.lua index 4f6b18e..acfa3ba 100644 --- a/init.lua +++ b/init.lua @@ -2,7 +2,7 @@ local Tactree = {} local Nodes = {} local function NodeStart(node, args) - -- abort if started + -- don't start again if started if node.data then return end node.data = node.parent and node.parent.data or args @@ -11,7 +11,7 @@ local function NodeStart(node, args) end local function NodeUpdate(node) - -- abort if not started + -- don't tick if not started if not node.data then return end local result = node:_tick() @@ -91,7 +91,7 @@ function Tactree.Tree(name) end end - return setmetatable(node, { __index = Nodes[name] }) + return setmetatable(node, { __index = Nodes[name], __tostring = function() return name end }) end Tactree.Leaf 'Sequence' @@ -142,6 +142,18 @@ Tactree.Leaf 'Selector' end } +Tactree.Leaf 'Inverter' +{ + start = function(node) + node.children[1]:start() + end, + tick = function(node) + local result = node.children[1]:update() + + if type(result) == 'boolean' then return not result end + end +} + Tactree.Leaf 'RepeatUntilFail' { start = function(node)