#How to add extra parameters to godot signals

14 messages · Page 1 of 1 (latest)

tame cipher
#

I want to send the variable "numero" in the signal "_on_body_entered", but if i put that extra parameter in both functions, the code i set for each function stops working (in the case of the player, it doesnt do the commented thing, in the case of numeros, they dont queue_free)

Im confused because this is kinda how the custom signals works

also, this is how i connected those two signals in the third image, i just saw i should put the parameter in that connection but i dont know how to do it

tacit gazelle
#

I think you can add custom parameters to built-in signals

#

if you add the parameters in the connect function

#

Like this:

func _ready() -> void:
  self.body_entered.connect(bodyEnterFunction, 12)

func bodyEnterFunction(_body : CharacterBody2D, param : int) -> void:
  print(param)
#

also, it's considered good practice to NEVER connect signals with the editor, and only connect signals using the .connect() function with code

modest crown
atomic flame
ocean spindle
# atomic flame stack overflow has this answer about binding extra arguments to a signal `object...

well this is also wrong. bind expects arguments to be passed one-by-one, if you want to pass them in an array like this, there is bindv: https://docs.godotengine.org/en/stable/classes/class_callable.html#class-callable-method-bindv

tacit gazelle
#

since connecting it with editor is too hard to manage

modest crown
#

That would be absurd; you'd have to make an entire extra script for every single level with a million string references; it would be harder to manage and easier to break. Yes, you can. No, you shouldn't.

tacit gazelle