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):
velocity.y = JUMPFORCE * 0.7

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


Here is my enemy code for this function
func _on_Topdetector_body_entered(body):
speed = 0

func _on_SideChecker_body_entered(body):

func _on_Timer_timeout():

: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( 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.