error calling method from signal (body_enter) ( completely entirely clueless :I )

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

hello

i’ve used godot for some time, but still am mostly a nooblet

having set up a lil tank, and getting it to shoot lazers, i proceeded to make them disappear upon hitting an obstacle. strangely enough, something goes wrong the moment body_enter signal is called.

i get this error (it doesn’t crash the game thou):
error calling method from signal (body_enter), expected 0 arguments

it’s really weird because the brackets in the “_hit()” function are empty (i assume this is where arguments usually reside?)

code, the object is an Area2D (sorry for raw paste, but i cant get the code frame thingy to work)

func _ready():
connect(“body_enter”,self,“_hit”)

func _process(delta):
v=Vector2(vb*sin(r)delta,vbcos(r)*delta)
set_rot(r)
get_node(‘sprit’).set_global_pos(self.get_global_pos().floor())

func _hit():
queue_free()

i used the body_enter signal many times in the past and this has never happened, so am quite confused. :<

Please, use the “code” button on the QA editor, don’t just paste it. To get it working, you should select your code, and then press it. (also, this is markdown, so if you just indent those lines with four spaces…)

Bojidar Marinov | 2016-02-29 13:34

:bust_in_silhouette: Reply From: volzhs

body_enter signal has a parameter which hit the body.

body_enter( Object body )

So, you should have parameter at func _hit()

func _hit(target):
    queue_free()

haha thanx!

i forgot about having to write ‘body’ beetwen the brackets… although then shouldn’t the error say ‘expected 1 argument’ instead of zero arguments? xD

w32.deadcode | 2016-02-29 13:58