0 votes

Hello all. I made a button that lets players mute the sound effects in my game. The variable "FXon" is in the top level Node/Panel's GDscript. Two layers below that, I have a child node with its own GDscript like this:

Node/Panel (a) -> Node/Control (b) -> Node/Control (c)

I tried this:

onready var globalVars = get_node("/root")
if globalVars.FXon == 1: do_stuff

Every time it got to that line of code, the game hung. So how can I read a's FXon value from c's GDscript? Thanks.

asked Apr 12 in Engine by lordbry (20 points)
edited Apr 12 by lordbry

1 Answer

+1 vote
Best answer

With get_node("/root") you will get the root-node of the tree which is a Viewport-node. When you run a scene, that scene will be added as a child of root. So if (a) is called "main", the correct path would be get_node("/root/main").

answered Apr 12 by njamster (9,818 points)
selected Apr 12 by lordbry
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 How to use this Q&A? before posting your first questions.