why does my enemy script keeping giving invalid call,non existent function?

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

i made an enemy called zombie. in its script I used a function called bounce which I declared in the main players script.

func _on_top_checker1_body_entered(body):
$AnimatedSprite.play("squash")
speed = 0
set_collision_layer_bit(4,false)
set_collision_mask_bit(0,false)
$top_checker1.set_collision_layer_bit(4,false)
$top_checker1.set_collision_mask_bit(0,false)
$sides_checker1.set_collision_layer_bit(4,false)

$sides_checker1.set_collision_mask_bit(0,false)
$Timer1.start()
body.bounce()

the bounce function is supposed to make the player bounce when it comes in contact with enemy.

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

this function was declared in main players script. how can I stop this error?

Does the error arise from this bit of the code, body.bounce()? If so, is the variable body an object of the main player’s script?

Ertain | 2020-08-30 18:07

i fixed the problem. all i needed to do was mention the functions above in the script. before I used it.

func bounce():                                                                                                                                                         
 pass

umar262005 | 2020-08-30 19:20

:bust_in_silhouette: Reply From: umar262005

solution is that i needed to mention the functions above in the script before using it in another function

func bounce():
       pass