Hi there.
I’m using behaviour tree for my objects. One of my task is about moving object from one point to another.
I can do it by sending msg to move_system script.
But in order to complete task in behaviour tree, I need to run task:success() function.
I can’t pass any function in message to move_system, due to engine restrictions.
I have some strange idea, but I don’t like it and I would like to hear your opinion.
-- I can create module callback_manager which will store references to functions
local callback_id = callback_manager:create(function task:success() end)
-- So I can send a message in my behaviour tree like this
msg.post(MOVE_SYSTEM, "move", { callback_id })
-- In move system, when object arrives at destination, it will check if callback_id exists, and then call
callback_manager:call(callback_id)
Another idea is to create state in behaviour tree script instance, to which I will assign callback for task.
So no callback_manager, but move_system will just send message “move_done” to behaviour tree script, and here I will use something like self.task:success()
Generally I don’t like both solutions, I think I am missing something.
Right now I’ve created module with class for my object, where I’m using go.animate in move function.
So in behaviour tree task I just use object:move(position, callback) which works perfectly, however I also don’t like idea that go.animate functions are used in modules, instead of dedicated script like move_system in my opinion. Too much OOP instead of using msg.
I have created three solutions, and I am not really sure which approach is the correct one, so as not to create spaghetti code.
Any advice?