Cannot get signal to work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By randor73


I am using an online tutorial to learn and have gotten to a spot that is baffling me. I have followed along and tried to make sure i am EXACT with the tutorial but for some reason the bullets are not appearing.
Below are my GD scripts, then the Eror log:


extends Area2D

export (int) var speed = 10

var direction := Vector2.ZERO

func _physics_process(delta: float) -> void:
    if direction != Vector2.ZERO:
	    var velocity = direction * speed
	    global_position += velocity

func set_direction(direction: Vector2):
    self.direction = direction


extends Node2D

func handle_bullet_spawned(bullet, position, direction):
    bullet.global_position = position


extends Node2D

onready var bullet_manager = $BulletManager
onready var player = $BulletManager

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
    player.connect("player_fired_bullet", bullet_manager, "handle_bullet_spawned")


extends KinematicBody2D

signal player_fired_bullet(bullet, position, direction)

export (PackedScene) var Bullet
export (int) var speed = 100

onready var end_of_gun = $EndOfGun

func _ready() -> void:
    pass # Replace with function body.

func _process(delta: float) -> void:
    var movement_direction := Vector2.ZERO

    if Input.is_action_pressed("up"):
	    movement_direction.y = -1
    if Input.is_action_pressed("down"):
	    movement_direction.y = 1
    if Input.is_action_pressed("left"):
	    movement_direction.x = -1
    if Input.is_action_pressed("right"):
	    movement_direction.x = 1

    movement_direction = movement_direction.normalized()
    move_and_slide(movement_direction * speed)


func _unhandled_input(event: InputEvent) -> void:
    if event.is_action_released("shoot"):
func shoot():
    var bullet_instance = Bullet.instance()
    var target = get_global_mouse_position()
    var direction_to_mouse = end_of_gun.global_position.direction_to(target).normalized()
    emit_signal("player_fired_bullet", bullet_instance, end_of_gun.global_position, direction_to_mouse)

Error Log:

E 0:00:01.225   connect: In Object of type 'Node2D': Attempt to connect nonexistent signal 'player_fired_bullet' to method 'Node2D.handle_bullet_spawned'.
  <C++ Error>   Condition "!signal_is_valid" is true. Returned: ERR_INVALID_PARAMETER
  <C++ Source>  core/object.cpp:1452 @ connect()
  <Stack Trace> @ _ready()

Any Ideas??

Thank you for your help

:bust_in_silhouette: Reply From: kidscancode

Your error is here:

player.connect("player_fired_bullet", bullet_manager, "handle_bullet_spawned")

But you’ve written

onready var player = $BulletManager

And the “BulletManager” does not have that signal.

Thank you,
However; I am still a bit confused?

am I missing a method to give the BulletManager the signal? This whole signal thing is new to me, so i am struggling a bit to wrap my head around it.

randor73 | 2020-07-23 17:39

Your code as it’s written is trying to connect a signal on the bullet manager to the bullet manager, because both bullet_manager and player are pointing at `BulletManager’.

Shouldn’t player be looking at `$Player’ ?

onready var player = $Player

“Player” has the signal. You want to connect the player’s signal to the bullet manager, I assume. Now this:

player.connect("player_fired_bullet", bullet_manager, "handle_bullet_spawned")

makes sense, because it’s saying “Connect the player’s ‘player_fired_bullet’ signal to the bullet_manager”.

kidscancode | 2020-07-23 17:44

OMG! Thank you!

Now that I see that it makes more sense… I guess im not sure why he didnt show that fix in the tutorial…

Very much appreciated!

randor73 | 2020-07-23 17:47