jecs/modules/BT/module.luau

44 lines
792 B
Text
Raw Normal View History

2026-01-26 03:28:14 +00:00
-- original author @centau
local SUCCESS = true
local FAILURE = false
local RUNNING = newproxy(false)
local function SEQUENCE(nodes: { (...any) -> boolean})
return function(...)
for _, node in nodes do
local status = node(...)
if not status or status == RUNNING then
return status
end
end
return SUCCESS
end
end
local function FALLBACK(nodes: { (...any) -> boolean })
return function(...)
for _, node in nodes do
local status = node(...)
if status or status == RUNNING then
return status
end
end
return FAILURE
end
end
local function NOT(f)
return function(...): boolean
return not f(...)
end
end
local bt = {
SEQUENCE = SEQUENCE,
FALLBACK = FALLBACK,
RUNNING = RUNNING,
NOT = NOT,
}
return bt