Skip to content

Commit

Permalink
fix: run initial transition on next frame
Browse files Browse the repository at this point in the history
fixes: #31
  • Loading branch information
derkork committed Sep 10, 2023
1 parent 7419d78 commit 59ae59b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.4] - 2023-09-10
### Fixed
- Fixed the ant hill demo which was broken in the last release ([#31](https://github.com/derkork/godot-statecharts/issues/31)).


## [0.4.3] - 2023-09-05
### Fixed
- The state chart now waits for the next frame after being ready to enter its initial state. This allows all nodes which are above the statechart in the three to finish their `_ready` phase and properly initialize before the state chart starts running ([#28](https://github.com/derkork/godot-statecharts/issues/28)).
Expand Down
2 changes: 1 addition & 1 deletion godot_state_charts_examples/ant_hill/ant/ant.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const SEGMENT_LENGTH = 150

func _ready():
# start the state chart
state_chart.send_event("initialized")
state_chart.send_event.call_deferred("initialized")


## Called when we are seeking for food and need a new target.
Expand Down
4 changes: 4 additions & 0 deletions manual/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ Now we send a `stop` event to the state chart. The currently active state is now

In deeper state charts, events will be passed to the active states going all the way down until an active leaf state (a state which has no more child states) is reached. Now all transitions of that state will be checked, whether they react to that event. If a transition reacts to that event it will be queued for execution and the event is considered as handled. If no transition handles a given event, the event will bubble up to the parent state until it is consumed or reaches the root state. If the event reaches the root state and is not consumed, it will be ignored.

> ⚠️ **Note:** The initial state of a state chart will only be entered one frame after the state chart's `_ready` function ran. It is done this way to give nodes above the state chart time to run their `_ready` functions before any state chart logic is triggered.
>
> This means that if you call `send_event` in a `_ready` function it will most likely not work as expected. If you must send an event in a `_ready` function, you can use `call_deferred` to delay the event sending by one frame, e.g. `state_chart.send_event.call_deferred("some_event")`.
#### Transitions on entering a state

It is possible to immediately transition elsewhere when a state is entered. This is useful for modeling [condition states](https://statecharts.dev/glossary/condition-state.html). To make a transition execute immediately when a state is entered, leave the _Event_ field empty. Usually you will put a guard on such a transition to make sure it is only taken when a certain condition is met.
Expand Down

0 comments on commit 59ae59b

Please sign in to comment.