Creating a Finite State Machine for turn-based combat - how to handle button input signals?

Godot Version

Godot 4.6

Question

I’m currently working on a prototype for a turn-based combat system, and I want to implement a Finite State Machine to handle the logic for turns. My current implementation of combat relies on using buttons to trigger the combat events:

image

I’ve worked on FSMs before for platformers, but I’m having some trouble wrapping my head around the logic for using them for turn-based combat.

For example, I’m not sure where of my FSMs built-in functions I can handle the logic for the button signals here.

class_name State 
extends Node

var state_machine: State

func enter() -> void:
	pass
	
func exit() -> void:
	pass
	
func update(_delta: float) -> void:
	pass
	
func _physics_update(_delta: float) -> void:
	pass

For those with any experience working on turn-based combat and state machine logic in Godot, what would be some good ways of going about this? Thank you.

whenever doing complex logic like turn based, I like to draw it out and see how the logic would look visually.

This was a quick mockup I made after thinking about how to create the logic for a simple turn based system.

In the mockup I assumed the max amount of enemies there could be is 3 and the third enemy always is a support for the other 2.

Personally I use excalidraw since its free and easy.

1 Like

This will be helpful to visualize things, thanks!

2 Likes