Created
August 1, 2022 21:52
-
-
Save Einlander/ea2edac214af688944159aa5eab176f8 to your computer and use it in GitHub Desktop.
Simple FSM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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