0 votes

I have 2 scenes. Scene 1 has 3 childs:
scene1 (Node2D) -> Button1 (Button) -> scene2 (scene2.tscn)
Scene 2 has one child:
scene2 (Node2D) -> Button2 (Button)

Scene1 has the following script:

var value = 1 # it is a global variable (autoload, named GlobalValue)
func _on_Button1_pressed():
            value = 5

Scene 2 has this script:

func _on_Button2_pressed():
         print(GlobalValue.value) # supposed to print 5, but prints 1

Basically what's happening is that the variable "value" is not changing after I try to change it when pressing a button.

Godot version 3.x
in Engine by (16 points)

Can you show an output of get_tree().root.print_tree_pretty() ?

 ┖╴root
    ┠╴GlobalValue
    ┖╴scene1
       ┠╴scene2
       ┃  ┖╴Button2
       ┖╴Button1

Nevermind, I just wrote GlobalValue.value = 5 and now it's works as intended.

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 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 webmaster@godotengine.org with your username.