How to check if the variable in a group is an equal value throughout

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SnapCracklins

I am working on Tic-Tac-Toe logic right now and I have my “victory lines” grouped together in Godot. I am trying to check if a variable, same name in all objects, is the same value. I am essentially using an array as a very simple state machine. The groups are called as arrays at start for the sake of mechanical clarity.

onready var myButtons = get_tree().get_nodes_in_group('all_buttons')
onready var row1 = get_tree().get_nodes_in_group('row_1')
onready var row2 = get_tree().get_nodes_in_group('row_2')
onready var row3 = get_tree().get_nodes_in_group('row_3')
onready var column1 = get_tree().get_nodes_in_group('column_1')
onready var column2 = get_tree().get_nodes_in_group('column_2')
onready var column3 = get_tree().get_nodes_in_group('column_3')
onready var across1 = get_tree().get_nodes_in_group('across_1')
onready var across2 = get_tree().get_nodes_in_group('across_2')

Each button node has a code like this:

var stateMachine = ["EMPTY", "HAS_X", "HAS_O"]
var state = stateMachine[0]

So my question:
How would I check this local “state” variable throughout the entire group at once with a method? Obviously I will check it in the Main Scene, I just need to know what process to use.

:bust_in_silhouette: Reply From: Inces
for node in get_tree()get_nodes_in_group(X) :
      var state = get_tree()get_nodes_in_group(X)[0]
      if node.state != state :
             return false
return true

Just something I came up now. Starts with first node state, if any iterated node state is different from it - function returns false ( tic tac unmatched ). If everything is the same, loop continues until it reaches return true ( tic tac matched )