Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(2 edits)

Better to do it like this, so func is not required to exist, and only called if it exists for each state, cleaner and more maintainable

func _physics_process(delta):
     if has_method(current_state + "_logic"):
         call(current_state + "_logic")
func set_state(new_state : String):
     #change values
     previous_state = current_state
     current_state = new_state
     #call methods
     if previous_state != null:
         if has_method(previous_state + "_exit_logic"):
             call(previous_state + "_exit_logic")
     if current_state != null:
         if has_method(current_state + "_enter_logic"):
             call(current_state + "_enter_logic")
#Define state functions below