0 votes

It gives me these errors:

1- Invalid argument for "connect()" function: argument 2 should be "Callable" but is "HurtBox".

2- Invalid argument for "connect()" function: argument 3 should be "int" but is "String".

code:

 class_name HurtBox
 extends Area2D

func _init() -> void:
    monitorable = false
    collision_mask = 2


func _ready() -> void:
    connect("area_entered", self, "_on_area_entered")
    pass


func _on_area_entered(hitbox: HitBox) -> void:
    print("done")
    if owner.has_method("take_damage"):
        owner.take_damage(hitbox.damage)
Godot version 4
in Engine by (16 points)

1 Answer

0 votes

I believe the syntax you're using is for godot 3.x and it has changed for godot 4.
Instead of:

connect("area_entered", self, "_on_area_entered")

Try this:

timeout.connect(_on_area_entered)

I believe the documentation on signals is updated to godot 4:
https://docs.godotengine.org/en/latest/getting_started/step_by_step/signals.html

by (112 points)
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 Frequently asked questions and 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 [email protected] with your username.