From 296cb41e452c0e4c40a83897d4c7752db4cad298 Mon Sep 17 00:00:00 2001 From: groug Date: Tue, 14 Feb 2023 16:24:53 +0100 Subject: [PATCH] README --- README | 1 - README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index 15a974e..0000000 --- a/README +++ /dev/null @@ -1 +0,0 @@ -icon: made by Freepik from https://www.flaticon.com, license: Creative Commons BY 3.0 diff --git a/README.md b/README.md new file mode 100644 index 0000000..14d75f5 --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +# Description +TODO +# How to use +- Add a Node2D node named "StateMachine" with the script state_machine.gd +- Initialize the states, initial state and conditions: +{{{ + $StateMachine.add_state("idle") + $StateMachine.add_state("hurt") + $StateMachine.add_state("dead") + $StateMachine.set_init_state("idle") + $StateMachine.add_transition("idle", "hurt", [], "fire") + $StateMachine.add_transition("hurt", "dead", ["has_stuff_been_handled", "is_dead"]) + $StateMachine.add_transition("hurt", "idle", ["has_stuff_been_handled"]) +}}} + +- Trigger an event +{{{ + $StateMachine.trigger("fire") +}}} + +- Add a condition: it's just a func returning a bool +{{{ + def has_stuff_been_handled(): + return true +}}} + +- Add callbacks for state entering/update/exiting: just add the state name in on_XXXXX_state_YYYY() +{{{ + func on_idle_state_enter(): + pass + + func on_idle_state_update(delta): + pass + + func on_idle_state_exit(): + pass +}}} +- Enabling debug mode (logs when changing states) +{{{ + $StateMachine.set_debug_enabled(true) +}}} + +- Get the current state +{{{ + $StateMachine.get_current_state() +}}} + +- Get the last known state (before the current one) +{{{ + $StateMachine.get_last_state() +}}} + +# Credits +icon: made by Freepik from https://www.flaticon.com, license: Creative Commons BY 3.0