Doc: Update examples to use `StringName`
This commit is contained in:
parent
ecf1e4b65f
commit
923587e6e2
|
@ -40,7 +40,7 @@ and point it to the proper node in the :ref:`BTPlayer<class_BTPlayer>` blackboar
|
||||||
|
|
||||||
extends BTCondition
|
extends BTCondition
|
||||||
|
|
||||||
@export var shape_var: String = "shape_cast"
|
@export var shape_var: StringName = &"shape_cast"
|
||||||
|
|
||||||
func _tick(delta) -> Status:
|
func _tick(delta) -> Status:
|
||||||
var shape_cast: ShapeCast3D = blackboard.get_var(shape_var)
|
var shape_cast: ShapeCast3D = blackboard.get_var(shape_var)
|
||||||
|
|
|
@ -110,7 +110,7 @@ Example 2: InRange condition
|
||||||
|
|
||||||
@export var distance_min: float
|
@export var distance_min: float
|
||||||
@export var distance_max: float
|
@export var distance_max: float
|
||||||
@export var target_var := "target"
|
@export var target_var: StringName = &"target"
|
||||||
|
|
||||||
var _min_distance_squared: float
|
var _min_distance_squared: float
|
||||||
var _max_distance_squared: float
|
var _max_distance_squared: float
|
||||||
|
|
|
@ -76,7 +76,7 @@ To register a transition and associate it with a specific event, you can use the
|
||||||
|
|
||||||
.. code:: gdscript
|
.. code:: gdscript
|
||||||
|
|
||||||
hsm.add_transition(idle_state, move_state, "movement_started")
|
hsm.add_transition(idle_state, move_state, &"movement_started")
|
||||||
|
|
||||||
In this example, we're registering a transition from the ``idle_state`` to the ``move_state``
|
In this example, we're registering a transition from the ``idle_state`` to the ``move_state``
|
||||||
when the ``movement_started`` event is dispatched.
|
when the ``movement_started`` event is dispatched.
|
||||||
|
@ -85,7 +85,7 @@ A transition can be also associated with no particular starting state:
|
||||||
|
|
||||||
.. code:: gdscript
|
.. code:: gdscript
|
||||||
|
|
||||||
hsm.add_transition(hsm.ANYSTATE, move_state, "movement_started")
|
hsm.add_transition(hsm.ANYSTATE, move_state, &"movement_started")
|
||||||
|
|
||||||
**Events are dispatched** with the :ref:`LimboState.dispatch<class_LimboState_method_dispatch>` method.
|
**Events are dispatched** with the :ref:`LimboState.dispatch<class_LimboState_method_dispatch>` method.
|
||||||
It's important to note that this method can be called from anywhere in the state machine hierarchy and outside of it.
|
It's important to note that this method can be called from anywhere in the state machine hierarchy and outside of it.
|
||||||
|
@ -187,8 +187,8 @@ Let's illustrate this with a practical code example:
|
||||||
hsm.add_child(idle_state)
|
hsm.add_child(idle_state)
|
||||||
hsm.add_child(move_state)
|
hsm.add_child(move_state)
|
||||||
|
|
||||||
hsm.add_transition(idle_state, move_state, "movement_started")
|
hsm.add_transition(idle_state, move_state, &"movement_started")
|
||||||
hsm.add_transition(move_state, idle_state, "movement_ended")
|
hsm.add_transition(move_state, idle_state, &"movement_ended")
|
||||||
|
|
||||||
hsm.initialize(self)
|
hsm.initialize(self)
|
||||||
hsm.set_active(true)
|
hsm.set_active(true)
|
||||||
|
@ -198,7 +198,7 @@ Let's illustrate this with a practical code example:
|
||||||
var dir: Vector2 = Input.get_vector(
|
var dir: Vector2 = Input.get_vector(
|
||||||
&"ui_left", &"ui_right", &"ui_up", &"ui_down")
|
&"ui_left", &"ui_right", &"ui_up", &"ui_down")
|
||||||
if dir.is_zero_approx():
|
if dir.is_zero_approx():
|
||||||
hsm.dispatch("movement_started")
|
hsm.dispatch(&"movement_started")
|
||||||
|
|
||||||
|
|
||||||
func _move_update(delta: float) -> void:
|
func _move_update(delta: float) -> void:
|
||||||
|
@ -208,4 +208,4 @@ Let's illustrate this with a practical code example:
|
||||||
velocity = desired_velocity
|
velocity = desired_velocity
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
if desired_velocity.is_zero_approx():
|
if desired_velocity.is_zero_approx():
|
||||||
hsm.dispatch("movement_ended")
|
hsm.dispatch(&"movement_ended")
|
||||||
|
|
|
@ -19,7 +19,7 @@ Here's an example of how you can interact with the :ref:`Blackboard<class_Blackb
|
||||||
|
|
||||||
.. code:: gdscript
|
.. code:: gdscript
|
||||||
|
|
||||||
@export var speed_var: String = "speed"
|
@export var speed_var: StringName = &"speed"
|
||||||
|
|
||||||
func _tick(delta: float) -> Status:
|
func _tick(delta: float) -> Status:
|
||||||
# Set the value of the "speed" variable:
|
# Set the value of the "speed" variable:
|
||||||
|
@ -114,7 +114,7 @@ In the following example, we have a group of agents, and we want to share a comm
|
||||||
|
|
||||||
extends BTAction
|
extends BTAction
|
||||||
|
|
||||||
@export var group_target_var: String = "group_target"
|
@export var group_target_var: StringName = &"group_target"
|
||||||
|
|
||||||
func _tick(delta: float) -> Status:
|
func _tick(delta: float) -> Status:
|
||||||
if not blackboard.has_var(group_target_var):
|
if not blackboard.has_var(group_target_var):
|
||||||
|
|
Loading…
Reference in New Issue