<4.2.1 Godot Version>
Question
Hello! Recently I found a script for Solitaire in Godot but it’s in Godot 3.0 version of the language. I’ve been translating it but got stuck on an issue I think has something to do with signals and how to connect them to functions on a different script. I’m still pretty new to this so I tried looking at the documentation for signals and couldn’t figure it out.
I’m trying to connect the signals from the “CardTexture” script with the functions from the “Board” script. So I added a preload of the “Board” script and tried doing this:
var board = preload("res://scripts/board.gd")
signal dragged
func _ready():
board = get_parent()
dragged.connect(_on_Card_dropped)
But it gives me this error message:
Identifier “_on_Card_dropped” not declared in the current scope.
Which I assume means I haven’t connected the two scripts correctly. Or the preload isn’t enough for the signal to call the function from the “Board” script.
This is the function I’m trying to call on the “Board” script (along with some others):
func _on_Card_dragged(_card, _position):
current_move = Move.new()
current_move.initialize(_card, slots, deck, pool)
current_move.card_back_in_pool.connect(update_pool_layout)
if _card.slot_idx >= 0:
var slot : CardSlot = slots[_card.slot_idx]
slot.remove_card(_card)
dragged_from = _card.slot_idx
_card.dragged_from = _card.slot_idx
if _card in pool:
card_drawn_from_pool = true
pool.erase(_card)
remove_frames()
update_label()
$HintTimer.stop()
And this is what was originally in the “CardTexture” script with the 3.0 syntax:
func _ready():
board = get_parent()
connect("dragged", board, "_on_Card_dropped")
With this error message:
Cannot pass a value of type “String” as “int”.
Invalid argument for “connect()” function: argument 3 should be “int” but is “String”.
Which I guess is the syntax issues from Godot 3.0 to 4.0. Any help would be greatly appreciated. I’ve been stuck on this for a while now and am not sure where to look next. Thank you in advance!