Class: BehaviorTree::TaskBase

Inherits:
NodeBase
  • Object
show all
Includes:
Validations::ProcOrBlock
Defined in:
lib/behavior_tree/tasks/task_base.rb

Overview

A task (leaf) node.

Direct Known Subclasses

Nop

Instance Method Summary collapse

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_tickObject



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