Godot Version
4.3
Question
I’m relatively new and I’m struggling to understand the best (or any) way to share information between different scenes and scripts via either the editor or code.
My current conundrum is this:
For context I’m working on a board-game style game.
I have a scene board
which is the board layout made up of a squares. The squares come in three types player_squares
, interloc_squares
, and central_squares
. It has a script attached called board.gd
In that script I have a function called space_pos_array()
that creates an array of the position of each type of square, then returns all of these arrays as a tuple. The return looks like this:
[[(890, 300), (740, 350), (580, 300)], [(10, 300), (160, 250), (320, 300)], [(450, 300)]]
The above order being [player_squares]
, [interlock_squares]
, and [centre_squares]
Next I call this function to divide out the tuple into separate arrays so they can be called as needed:
var spaces = space_pos_array()
var player_space_list : Array = spaces[0]
var interloc_space_list : Array = spaces[1]
var centre_space_list : Array = spaces[2]
Now I want to access the player_space_list
array in another script called player_blocks.gd
which is attached to the parent node of a scene called player_block
How do I do this?
I’ve tried to research this myself and have read about globals/autoloads/singletons, signals, instantiation, etc. I’m feeling a bit overwhelmed and stuck in tutorial hell. I’m not sure what is the best way to do what I need, and anything I try doesn’t seem to work as I expect.