Godot Version
Godot 4.5 Stable
Question
I’ve been getting this weird issue when using setter functions in my small minesweeper type game
This is the structure of each tile instance in the scene:
UiButton #seen as $".." in the code, reacts to inputs and changes of variables
|_StaticBody2D #seen as $"Processor" in code, stores all variable
|_CollisionShape2D
|_Raycast * 8
When i started making it, i put everything inside a _process() function just to see if the stuff i wrote is actually working and then optimize it later on. It was all working fine, until i went to optimize it, i wanted it so that the button only updates when the variable for it being revealed changes, like this, using a setter function:
#Variables are stored in the StaticBody2D
@export var Revealed:bool:
set(v):
if Revealed == true:
print("working")
$"..".hasrevealed()
but when i do this, i get a stack overflow error that crashes the game, something that never happened when i used _process() with errors being reported in three different location in the stack, one in the setter function on the $"..".hasrevealed() line, and another two on the snippets below:
#Snippet comes from the Raycasts
if $"..".NearbyMines == 0 and #all other conditions are met...
print(str(name) + "quickrevealcalled")
get_collider().Revealed = true #this is the line where the error is reported
print("revealing "+ str(get_collider().name))
#Script comes from UiButton
if $Processor.NearbyMines == 0 and $Processor.IsMine == false:
print(str(name)+"istryingtocallquickreveal")
$Processor/Down.quickreveal()#error is reported on the first two
print("calledD")
$Processor/Up.quickreveal() #so this one is also included
print("calledU")
$Processor/Right.quickreveal()#but not this one or the others below
print("calledR")
...
and the game crashes…
the terminal output looks something like this:
400 #number of mines present in the grid
checkbuttonclick #print to see if it actually went through
@Button@211istryingtocallquickreveal #which tile has called quickreveal
Downquickrevealcalled #raycast being called
@Button@231istryingtocallquickreveal
Downquickrevealcalled
#...a bunch of other buttons were revealed here in the same structure as above, just with different names
@Button@351istryingtocallquickreveal
Downquickrevealcalled
@Button@371istryingtocallquickreveal #from here on it starts to repeat
Downquickrevealcalled
@Button@391istryingtocallquickreveal
calledD #and only now it prints the check?????
Upquickrevealcalled
@Button@371istryingtocallquickreveal
Downquickrevealcalled
@Button@391istryingtocallquickreveal
calledD
i wanted it to work so once the UiButton detects its been left clicked, it goes to it’s child Processor, sets the Revealed variable to true, which the processor then detects and reports back to it’s parent button, to then act on if the ammount of mines near it is 0 or it is a mine. If there are no nearby mines, it calls quickreveal on every raycaster child, which then causes the processor of other tiles to report they have been revealed that then opens up a cave, like an actual game of minesweeper, but for some reason it keeps breaking and i have no clue how to fix it
tbf i already read another topic that ran into a similar issue to mine while also coincidentally also making a minesweeper clone in a somewhat similar structure as to what im doing now, but none of the fixes proposed on that forum post have helped me because the issue doesnt seem to happen in the same place, this is somewhat a last resort for me because i can’t seem to find a fix for it anywhere
any help would be much appreciated! thanks for reading!