From 44226424587d199158073cf21f2b78014202f42c Mon Sep 17 00:00:00 2001 From: Shylie Date: Thu, 27 Jun 2024 15:31:21 -0400 Subject: [PATCH] Add more built-in node types --- init.lua | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 1ec3334..4f6b18e 100644 --- a/init.lua +++ b/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 -------------