Class: BehaviorTree::TaskBase
- Inherits:
-
NodeBase
- Object
- NodeBase
- BehaviorTree::TaskBase
- Includes:
- Validations::ProcOrBlock
- Defined in:
- lib/behavior_tree/tasks/task_base.rb
Overview
A task (leaf) node.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(procedure = nil, &block) ⇒ TaskBase
constructor
A new instance of TaskBase.
- #on_tick ⇒ Object
Methods included from BehaviorTree::TreeStructure::Algorithms
#cycle?, #each_node, #repeated_nodes, #uniq_nodes?
Constructor Details
#initialize(procedure = nil, &block) ⇒ TaskBase
Returns a new instance of TaskBase.
8 9 10 11 12 13 14 |
# File 'lib/behavior_tree/tasks/task_base.rb', line 8 def initialize(procedure = nil, &block) validate_proc!(procedure, block) super() @task_block = block_given? ? block : procedure end |
Instance Method Details
#on_tick ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/behavior_tree/tasks/task_base.rb', line 16 def on_tick raise 'Node should be set to running' unless status.running? return unless @task_block.is_a?(Proc) if @task_block.lambda? args = [@context, self].take @task_block.arity @task_block.(*args) else instance_eval(&@task_block) end end |