How to pass arguments through a signal to a new function?

Godot Version

4.3

Question

I wanna to pass through the speed to the parallax Background. What the right sytax to do this?

i want to increase the parallax scrolling with the speed to simulated more speed

The Code in the Player Script

signal current_speed(speed:float)

func _physics_process(delta):
	current_speed.emit(velocity.y)

The Code in the Background:

func _ready() -> void:
	bird.current_speed.connect(_calculate_scroll(speed))

func _calculate_scroll(bird_speed:float):
	print(bird_speed)

i get the error in the background “speed” is not declared in current scope

The syntax is the following:

func _ready() -> void:
	bird.current_speed.connect(_calculate_scroll)

func _calculate_scroll(bird_speed:float):
	print(bird_speed)

The argument gets passed automatically. if you want to add custom arguments you can use “bind”:

bird.current_speed.connect(_calculate_scroll.bind("my_extra_argument"))

or unbind a given number of arguments:

bird.current_speed.connect(_calculate_scroll.unbind(1))
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.