Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | FabianSchick123 |
How can i get access to my highest skript in my game because i want to get a variable from there.
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | FabianSchick123 |
How can i get access to my highest skript in my game because i want to get a variable from there.
Reply From: | johnygames |
In the script named Foo.gd we have the variable named example
, which has a value of 3
var example = 3
In another script named Bar.gd we access Foo’s example variable by using the following code:
onready var Foo = load("res://Scripts/Foo.gd") #path to script
func _ready():
var foo = Foo.new().example
print(foo) # this will print out 3
The main idea of this method is that you create a script that contains which autoloads at the beginning of your game and which you can access at any moment by calling get_node("/root/<resource_name>")