Hurt State on State Machine

Godot Version v4.3

Hi all, I’m trying to code a function that calls the “Hurt” state on my State Machine but I’m stuck on how to do it. Here’s what I tried to do:

On the Player node:

  1. This function receives value from Signal. It comes negative (-Value) to remove health and positive (+Value) to heal.
func _On_Player_Damaged(Value) -> void:
	is_hurt(Value)
	
	player_attributes.Current_Health += Value
	print(player_attributes.Current_Health)
  1. Then this function determines if the player is taking damage (-Value).
func is_hurt(Value) -> bool:
	if Value < 0:
		return true
	else:
		return false

On the States of the State Machine:
3. This function calls for the “Hurt” State if is_hurt() is true.

func _on_next_transitions() -> void:
	if player.is_hurt():
		transition.emit("Hurt")

But I get the error “Parser Error: Too few arguments for “is_hurt()” call. Expected at least 1 but received 0.” at the States and on the is_hurt() function at the Player node I get the error that I can’t use an int with a boolean…

Is it possible to get this to work? Also, how can I implement a cooldown so the Hurt animation doesn’t get spammed if the player receives lots of damage?

Greetings and thank you for the help.

Functions have so-called ‘signatures’. A signature consists of its return type and the types of all its input parameters. The signature of is_hurt in player is:

  • return type: bool
  • input parameters: precisely one, of type Variant

When you call a function, the arguments provided to the function must exactly match the signature, and the call to is_hurt in the state machine state does not do that. The function expects one argument, but instead it’s given no arguments. So that’s why Godot complains.

2 Likes

Thanks, I try to read all I can but sometimes this kind of information is hard to get by or to understand it’s what I’m missing hahaha

So, I created a new var to hold Value inside the function and remove the inputs, and it worked. Now I just gotta find out how to switch it back to false and put a cooldown to stop the animation from repeating but a step was taken so all good. :slight_smile:

1 Like