Add inverter node
This commit is contained in:
parent
4422642458
commit
342168c6c6
18
init.lua
18
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)
|
||||
|
Loading…
Reference in New Issue
Block a user