Collision between Area2D nodes problem

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By worstprogrammer
:warning: Old Version Published before Godot 3 was released.

So im making a simple 2D game and im having some problems with collision.
I want my character to basically die,trigger a Particle2D node and restart the scene when he collides with an object.When he collides the game crashes and i get the error:

Invalid call. Nonexistent function ‘defeat’ in base ‘Area2D (player.gd)’

The obstacle node is connected to on_obstacles_

This is the code on the player script :
var defeated=false

func _defeat():
	if(defeated):
		return
			
	get_node("player_sprite").hide()
	get_node("explosion").set_emitting(true)
	
	defeated(true)

And this is the code in the obstacle script :

 func _on_obstacles_area_enter( area ):
	if(area.get_name()=="player"):
		area.defeat()
	

Idk why the script doesnt recognize the defeat function on the player script.
Thanks,

Reddit - Dive into anything

atze | 2016-06-27 05:35

:bust_in_silhouette: Reply From: JTJonny

Try func defeat(): instead of func _defeat():

Tried it,got this error:

Invalid call to function ‘defeat’ in base ‘Area2D (player.gd)’. Expected 0 arguments.

Im still lost …

worstprogrammer | 2016-06-27 00:54

You sure it didn’t say invalid call to function ‘defeated’ in base ‘Area2D (player.gd)’. Expected 0 arguments.

because this defeated(true) might need to be changed to defeated = true.

These are a good read, and it might clear somethings up for you.
GDScript reference — Godot Engine (latest) documentation in English
http://docs.godotengine.org/en/latest/reference/gdscript_more_efficiently.html

JTJonny | 2016-06-27 01:07