How to FIX invalid call. nonexistent function ouch in base tile map

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

this is my main character call where i create function

extends KinematicBody2D

var velocity = Vector2(0,-1)
var coins = 0
const SPEED = 300
const JUMPFORCE = -940
const GRAVITY = 40
func _physics_process(delta):
if Input.is_action_pressed(“Right”):
velocity.x = SPEED
$Sprite.flip_h = false
elif Input.is_action_pressed(“Left”):
velocity.x = -SPEED
$Sprite.flip_h = true

if not is_on_floor():
velocity.y = velocity.y + GRAVITY

if Input.is_action_just_pressed("Jump") and is_on_floor():
	velocity.y = JUMPFORCE 
if Input.is_action_pressed("Crouch") and is_on_floor():

velocity = move_and_slide(velocity,Vector2.UP)
velocity.x = lerp(velocity.x,0,0.2)

func _on_Area2D_body_entered(body):

func bounce():
velocity.y = JUMPFORCE * 0.7

func hurt(var enemyposx):
velocity.y = JUMPFORCE * 0.5

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

func _on_Timer_timeout():

func _on_Trophy_body_entered(body):

func _on_Coin_body_entered(body):

Here is the enemy one where I use the function

extends KinematicBody2D

var speed = 50
var velocity = Vector2()
export var direction = -1
export var detects_cliffs = true

func _ready():
if direction == 1:
$AnimatedSprite.flip_h = true
$Floorchecker.position.x = $CollisionShape2D.shape.get_extents().x * direction
$Floorchecker.enabled = detects_cliffs
if detects_cliffs:
func _physics_process(delta):

if is_on_wall() or not $Floorchecker.is_colliding() and detects_cliffs and is_on_floor():
	direction = direction * -1
	$AnimatedSprite.flip_h = not$AnimatedSprite.flip_h
	$Floorchecker.position.x = $CollisionShape2D.shape.get_extents().x * direction

velocity.y += 20

velocity.x = speed * direction
velocity = move_and_slide(velocity,Vector2.UP)

func _on_Topdetector_body_entered(body):
speed = 0

func _on_Sidechecker_body_entered(body):

func _on_Timer_timeout():

:bust_in_silhouette: Reply From: Bean_of_all_Beans

So the signal tied to the function _on_Sidechecker_body_entered will call that function every time it detects any sort of body entering its area – RigidBody, StaticBody, or KinematicBody. What is happening is you have no type checking; you are just assuming that whenever _on_Sidechecker_body_entered is called, it will always be whatever body with a script that defines ouch. This can be fixed by checking to see if the body is the one you actually want – the player body. One simple method is by calling the body’s has_method method:

if body.has_method("ouch"):

That is one way of doing it; another would be to check the name of the body (, but this would cause problems if the name in the SceneTree does not exactly match, and probably should be avoided.