![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | pinteco |
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.
Can you show an output of get_tree().root.print_tree_pretty()
?
sash-rc | 2021-08-12 13:59
┖╴root
┠╴GlobalValue
┖╴scene1
┠╴scene2
┃ ┖╴Button2
┖╴Button1
pinteco | 2021-08-12 15:56
Nevermind, I just wrote GlobalValue.value = 5 and now it’s works as intended.
pinteco | 2021-08-12 16:19