diff --git a/CHANGES.md b/CHANGES.md index 211790d..1c68511 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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)). diff --git a/godot_state_charts_examples/ant_hill/ant/ant.gd b/godot_state_charts_examples/ant_hill/ant/ant.gd index f46e37a..8c5e329 100644 --- a/godot_state_charts_examples/ant_hill/ant/ant.gd +++ b/godot_state_charts_examples/ant_hill/ant/ant.gd @@ -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. diff --git a/manual/manual.md b/manual/manual.md index 021dbeb..4b97ff6 100644 --- a/manual/manual.md +++ b/manual/manual.md @@ -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.