Skip to content

Instantly share code, notes, and snippets.

@Einlander
Created August 1, 2022 21:52
Show Gist options
  • Save Einlander/ea2edac214af688944159aa5eab176f8 to your computer and use it in GitHub Desktop.
Save Einlander/ea2edac214af688944159aa5eab176f8 to your computer and use it in GitHub Desktop.
Simple FSM
# https://www.reddit.com/r/godot/comments/rfzwom/sexystupid_state_machine_in_8_lines/
class_name StateMachine extends Node
signal state_changed
var state:int = 0 setget _set_state
func _init(inital_state:int = 0) -> void:
state = inital_state
pass
func _set_state(new_state:int) -> void:
var old_state: int = state
if new_state == old_state: return
state = new_state
emit_signal("state_changed",old_state,new_state)
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment