Error when starting the scene: Invalid get index ‘Level’ (on base: ‘Node (Character.gd)’].
Can’t find any solution - already tried to use arrays but parsing error by debugger is the same.
Normally one would have to specify a class’s path to get it’s reference and by making it and autoload you essentially make it a Global class to be accessed throughout the entire project
Label.gd
extends Label
var PlayerLevel = Character.Level # should now work
func _ready():
print(PlayerLevel)
I just mind asking: Is it neccessary as single standing script with no extension using the line “extends Node” as there is no node that references to it?
I saw that these line is not inside your first global variable script.
If it is like I assume, I understand the error way better as Godot searching a node with global references which does not exists?
Fyrion | 2021-12-02 07:02
No that was my bad a typo if you will, repaired
It must extend a Node as it will be added to the sceneTree
For everybody: I found the solution with the help of those both guys.
I tried to use a int from a global variable in a label which only displays strings.
extends Label #Displaying current level on base of global variable
var PlayerLevel = GlobalVariables.PlayerLevel
func _ready():
set_text(str(PlayerLevel))