My project is getting bigger and has lots of states for the state machine. Unfortunately, it seems that I constantly have to use boolean switches to prevent parts of the code from being looped more than once.
Stuff like this pseudocode:
EnemyAttackState.gd:
func _process(delta):
enemy.attack()
func attack():
enemy.move_towards_player()
if distance to player <= 5:
enemy.stop()
enemy.animation_player.play("attack")
if executed_once == false:
player.take_damage(weapon.damage_dealt)
executed_once = true
enemy_statemachine.transition_to("Enemy Idle State")
This is only a simple example, but I have a lot of complex functions in my project that alternate between parts that have to be looped by the process function and parts that should only be executed once. Is there a way to have a function like the example above, e.g. that moves the enemy to a target but deals damage only once?
I'm new to Godot and coding, but my feeling tells me that this is probably bad practice. I know about signals but it seems like such a hassle to set up hundreds of signal connections.... Is there a more elegant way? Or is it OK to do stuff like this?