Invalid get index on base GDScript when trying to access autoload variable

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

For context:
I am following a tutorial for GodotSteam: https://www.youtube.com/watch?v=si50G3S1XGU&t=722s

I’m at min 15:30 right now where we’re trying to run the project without having Steam running on purpose. The expected result was to get a “failed to initialize Steam” message.

The error:
Instead, I get an error from Godot:
Invalid get index 'STEAM_NAME (on base: 'GDScript')

I made a script steam_name.gd with the class_name SteamMain. The script has a member variable declared as such:

extends Node
class_name SteamMain


var STEAM_NAME := "Name"

I initialized it with the value “Name” for testing purposes. I autoload steam_main.gd. I am sure this script actually loads, I made it print “test” in the ready function and I see that in the Output before the error occurs.

The error occurs here in my script lobby.gd which is attached to my Lobby scene, the current main scene of the project:

func _ready() -> void:
	steam_name_label.text = SteamMain.STEAM_NAME

steam_name_label is just a label node in the scene:

onready var steam_name_label = $SteamNameLabel

Does anyone know why this error occurs? I’m on version v3.1.2.
(Sorry for the excessive detail in this question, better safe than sorry)

:bust_in_silhouette: Reply From: cascas

Your autoload script name may be different because you are referencing autoloads not based on their class name, but based on their autoload name. In the autoload menu, make sure the name of steam_main.gd is SteamMain.

That was exactly it, thank you! An alternative solution for others looking at this question: removing the class_name altogether and just using steam_main.STEAM_NAME also solves this.

Kajice | 2021-01-24 18:39