Variables "partially reset" when instancing multiple times

Godot Version



Im sorry for the vague title, im very confused.
I have a GridContainer with multiple instances of a button, initialized thus:

func _ready():
	var scene = get_node("../Boardbutton2")
	for i in range(gridsize):
		for j in range(gridsize):
			var instance = scene.duplicate() = "field %s %s " % [i,j] 
			get_child(get_child_count()-1).row = i
			get_child(get_child_count()-1).column = j
			print("sent ", i, j)

to get the buttons to track their position in the grid. the parts of the button relevant to my question are these:

extends Button

var row = -1
var column = -1

func _on_gamelogic_move_is_valid(i,j,player,captured):
	print("buttonknows ", i, j)
	print(row, column)
func _pressed():
	print("pressed ", row, column)
	pressed.emit(row, column)

For some reason, the variables row and column in the _pressed function retain the correct value, but row, column in the _on gamelogic… function are -1 and -1.
even after it prints -1 as a value for them, pressing the button again does print the correct value. i never assign any values to row, column except when initializing the variables and in the _ready function of the gridcontainer.

Thanks in advance for any help, i feel like im losing my mind.

In case someone stumbles over this while googling: the issue was that the signal didnt connect automatically to the duplicates of the scene, and it was the “base copy” that was giving me the false output.

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