Class: BehaviorTree::Nop
- Defined in:
- lib/behavior_tree/tasks/nop.rb
Overview
An empty task that does not do anything. It requires N ticks to complete. It can be set to end with failure.
Instance Method Summary collapse
- #halt! ⇒ Object
-
#initialize(necessary_ticks = 1, completes_with_failure: false) ⇒ Nop
constructor
A new instance of Nop.
- #on_tick ⇒ Object
Methods included from TreeStructure::Algorithms
#cycle?, #each_node, #repeated_nodes, #uniq_nodes?
Constructor Details
#initialize(necessary_ticks = 1, completes_with_failure: false) ⇒ Nop
Returns a new instance of Nop.
10 11 12 13 14 15 16 17 |
# File 'lib/behavior_tree/tasks/nop.rb', line 10 def initialize(necessary_ticks = 1, completes_with_failure: false) raise ArgumentError, 'Should need at least one tick' if necessary_ticks < 1 super() @necessary_ticks = necessary_ticks @completes_with_status = completes_with_failure ? NodeStatus::FAILURE : NodeStatus::SUCCESS reset_remaining_attempts end |
Instance Method Details
#halt! ⇒ Object
27 28 29 30 |
# File 'lib/behavior_tree/tasks/nop.rb', line 27 def halt! super reset_remaining_attempts end |
#on_tick ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/behavior_tree/tasks/nop.rb', line 19 def on_tick @remaining_ticks -= 1 return if @remaining_ticks.positive? status.set @completes_with_status reset_remaining_attempts end |