How to fix Invalid call. Nonexistent function 'ouch' in base 'TileMap'

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By koosha

I am trying to get a function from my main play to an enemy. This is the character code

func ouch(var posx):
set_modulate(Color(1,0.3,0.3,0.3))
velocity.y = JUMPFORCE * 0.7

if position.x < posx:
	velocity.x = -800
elif position.x > posx:
	velocity.x = 800

Input.action_release("Left")
Input.action_release("Right")

Here is my enemy code for this function
func _on_Topdetector_body_entered(body):
$AnimatedSprite.play(“Dead”)
speed = 0
set_collision_layer_bit(4,false)
set_collision_mask_bit(0,false)
$Topdetector.set_collision_layer_bit(4,false)
$Topdetector.set_collision_mask_bit(0,false)
$SideChecker.set_collision_layer_bit(4,false)
$SideChecker.set_collision_mask_bit(0,false)
$Timer.start()
body.bounce()
$Kill.play()

func _on_SideChecker_body_entered(body):
body.ouch(position.x)

func _on_Timer_timeout():
queue_free()

:bust_in_silhouette: Reply From: jgodfrey

In this specific cast, your bodyentered method is being triggered by a collision with a TileMap node. I’d suggest that you temporarily remove the call to body.ouch(position) in that function and replace it with a print(body.name) to get a better understanding of what bodies are triggering the method.

Essentially, you’ll want to only call your ouch function if the the collision has been triggered by a body that really has an ouch function. You can do that any number of ways including checking for the name of a specific body, or checking that the body is in a given group, or by explicitly checking that the body has an ouch method.

Bottom line, don’t attempt to blindly call ouch on anything that triggers the collision.