Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TreeProto:run(dt)
- if self.running then
- -- warn(debug.traceback("Tried to run BehaviorTree while it was already running"))
- return
- end
- local nodes = self.nodes
- local obj = self.object
- local i = self.index
- local nodeCount = #nodes
- local didResume = self.paused
- self.paused = false
- self.running = true
- local nodeResult -- MY EDIT *******************************************************************************
- while i <= nodeCount do
- local node = nodes[i]
- if node.type == "task" then
- local task = node.task
- if didResume then
- didResume = false
- elseif node.start then
- node.start(task, obj, dt)
- end
- node.status = nil
- node.run(task, obj, dt)
- if not node.status then
- warn("node.run did not call success, running or fail, acting as fail")
- node.status = "fail"
- end
- if node.status == "running" then
- self.paused = true
- break
- elseif node.status == "success" then
- if node.finish then
- node.finish(task, obj, dt)
- end
- i = node.onsuccess
- nodeResult = "success" -- MY EDIT *******************************************************************************
- elseif node.status == "fail" then
- if node.finish then
- node.finish(task, obj, dt)
- end
- i = node.onfail
- nodeResult = "fail" -- MY EDIT *******************************************************************************
- else
- error("bad node.status")
- end
- elseif node.type == "random" then
- i = node.indices[math.random(1, #node.indices)]
- else
- error("bad node.type")
- end
- end
- self.index = i <= nodeCount and i or 1
- self.running = false
- -- MY EDIT *******************************************************************************
- if i == nodeCount+1 then
- return nodeResult
- else
- return "running"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement