0 votes


i'm currently learning the ins and outs of godot (especially the script part) and i've come across a problem i don't understand on a conceptual level and i hope to find the underlying problem and solution here.

i'm practising around with a checkers game and would like to manipulate variables from one script to another like this:
the tree looks like this with the Game Node being the root

  1. Game Node
  2. Board Sprite
  3. Control Node
  4. Button Node

The Game Node handles the setup process and is in control of the board and its functionality. Inside of it, there is a 2D array called board2d that is 8x8.
Since i want to populate the board with the red and blue stones of the players, i want to update the board
2d array from another script with a function called set_stone_on_board(x, y, stone):
Because my button is so far down in the tree, i have to make the call like this (which is almost definitely not the way to go but i couldnt find anything better and using the full res:// patch didnt work for me):

get_node("..").get_node("..").get_node("..").set_stone_on_board(1, 1, stone)

unfortunately my board_2d array is empty upon calling and i dont quite understand why that is since i didnt change the scene and the game node is a parent node of the button

Could anyone bring light to my darkened mind?

Also any form of "it might be better to use/do this that way" is appreciated :)

Thanks in advance

in Engine by (12 points)

Choose your hack :b

  • You can access a node with absolute path: get_node('/root/scene_node/Game Node');
  • You can emit a signals;
  • You can use globals/singleton with a reference to the array;
  • You can pass the Game Node as reference;

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.