0 votes

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 onobstacles

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,

in Engine by (15 points)
edited by

1 Answer

+1 vote
Best answer

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

by (543 points)
selected by

Tried it,got this error:

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

Im still lost ..

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.
http://docs.godotengine.org/en/latest/reference/gdscript.html
http://docs.godotengine.org/en/latest/reference/gdscript_more_efficiently.html

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.