Help! Line 7:Cannot pass a value of type "String" as "int". Line 7:Invalid argument for "connect()" function: argument 3 should be "int" but is "String"

Hello, i have been working on a top down shooter sort of like hotline miami in terms of gameplay, and i have been following a tutorial for shooting, but i get these errors:

Line 7:Cannot pass a value of type “String” as “int”.
Line 7:Invalid argument for “connect()” function: argument 3 should be “int” but is “String”.

this error is in this code for the main level so far:

extends Node2D

@onready var bullet_manager = $bulletmanager
@onready var player = $player

func _ready() -> void:
    player.connect("player_fired_bullet", bullet_manager, "handle_bullet_spawned")

here is the code for the player:

extends CharacterBody2D

signal player_fired_bullet(bullet)

@export var speed: float = 100
@export var accel: float = 10
@export var Bullet :PackedScene 


@onready var end_of_gun = $endofgun
@onready var anim_sprite: AnimatedSprite2D = $AnimatedSprite2D as AnimatedSprite2D

func _physics_process(_delta: float) -> void:
	var direction: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
	
	velocity.x = move_toward(velocity.x, speed * direction.x, accel)
	velocity.y = move_toward(velocity.y, speed * direction.y, accel)
	
	look_at(get_global_mouse_position())
	move_and_slide()


func _unhandled_input(event: InputEvent) -> void:
	if event.is_action_pressed("shoot"):
		shoot()

		
		
		
		
func shoot():
	var bullet_instance = Bullet.instantiate()
	bullet_instance.global_position = end_of_gun.global_position
	var target = get_global_mouse_position()
	var direction_to_mouse = bullet_instance.global_position.direction_to(target).normalized()
	bullet_instance.set_direction(direction_to_mouse)
	emit_signal("player_fired_bullet", bullet_instance)

here is the code for the bullet:

extends Area2D

@export var speed: int = 15


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

This is the tutorial that i have been following: https://www.youtube.com/watch?v=9RP7Ujv0gdE

I have been using godot 4.2.2 but the tutorial uses some version of godot 3

I would really appreciate help, thank you!

:slight_smile:

player.player_fired_bullet.connect(handle_bullet_spawned.bind(bullet_manager))

or

player.connect("player_fired_bullet",handle_bullet_spawned.bind(bullet_manager))
1 Like