How can i get acces to my highest Skript in Game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By FabianSchick123

How can i get access to my highest skript in my game because i want to get a variable from there.

:bust_in_silhouette: Reply From: johnygames
  1. One way to do that is by loading the script in question into another script. From there you can access the variable. Here’s and example:

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
  1. Another way is by using so-called singletons, which are basically global variables and functions you can access from anywhere in your game:
    Singletons (AutoLoad) — Godot Engine (3.1) documentation in English

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>")