behaviourtree.lua icon indicating copy to clipboard operation
behaviourtree.lua copied to clipboard

Arguments to node instances

Open rubenwardy opened this issue 5 years ago • 0 comments

I'd like to provide arguments to an instance of a task. Currently, I do that by creating an entire new node type:

local function create_action_task(params)
	return BehaviourTree.Task:new({
		run = function(self, entity)
			local action = entity:set_action_if_not_set(unpack(params))
			if action:is_complete() then
				self:success()
			else
				self:running()
			end
		end,
	})
end

local bt = BehaviourTree:new({
	tree = BehaviourTree.Sequence:new({
		nodes = {
			create_action_task({ rvwp.entity.actions.go_to, Vector:new(4, 5, 0) }),
			create_action_task({ rvwp.entity.actions.go_to, Vector:new(16, 5, 1) }),
		}
	})
})

bt:setObject(entity)

is there a better way to do this?

rubenwardy avatar Mar 01 '20 01:03 rubenwardy