0 votes

I want to connect a signal in a script but I get the following error:

SCRIPT ERROR: Parse Error: Invalid argument for "connect()" function: argument 2 should be Callable but is res://characters/EnemySpawner.gd

This is the code:

enemy.connect("enemy_died", self, "score")

Godot version 4.0
in Engine by (19 points)

3 Answers

+1 vote

Godot 4.0 is pre-alpha software. It is not ready for use, and does not work in the same way as 3.x. You should not be using it if you are a beginner.

by (20,677 points)
0 votes

I know my answer is two months late, but I hope it helps someone

I think it is now

$objectname.signal.connect(func() : pass)

example

$enemy.enemy_died.connect(func() : do something)

the example above was inline

here is an example with the other way

var onEnemyDied = func():
    pass #do something

$enemy.enemy_died.connect(onEnemyDied)
by (21 points)
0 votes

I think this might help you.

$Button.connect("pressed", self, "_on_button_pressed")

will become

$Button.pressed.connect(self._on_button_pressed)

To make a signal with additional arguments, you would use the new Callable.bind():

$Button.pressed.connect(self._on_button_pressed.bind("Hello", "World"))

Signals will now have their own class, and therefore their own methods. This includes the ability to emit signals through code:

$Button.pressed.emit()

Disconnect signals:

$Button.pressed.disconnect(self._on_button_pressed)

Get all current connections:

$Button.pressed.get_connections()

Check if the signal is connected:

$Button.pressed.is_connected(self._on_button_pressed)
by (16 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 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.