bovido/addons/beehave/nodes/leaves/blackboard_has.gd
Mathilde Grapin 1aed988149 Add a behavior tree to the enemy
Add the Beehave addon.
Make the enemy do the same thing as before but with a behavior tree.
2023-06-12 16:48:35 +02:00

24 lines
723 B
GDScript

## Returns [code]FAILURE[/code] if expression execution fails or the specified key doesn't exist.
## Returns [code]SUCCESS[/code] if blackboard has the specified key.
@tool
class_name BlackboardHasCondition extends ConditionLeaf
## Expression representing a blackboard key.
@export_placeholder(EXPRESSION_PLACEHOLDER) var key: String = ""
@onready var _key_expression: Expression = _parse_expression(key)
func tick(actor: Node, blackboard: Blackboard) -> int:
var key_value: Variant = _key_expression.execute([], blackboard)
if _key_expression.has_execute_failed():
return FAILURE
return SUCCESS if blackboard.has_value(key_value) else FAILURE
func _get_expression_sources() -> Array[String]:
return [key]