Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | magicwings |
I have a file called skill_move.gd
that contains the following:
extends Node
enum Skill {
Jump,
Backflip,
DoubleBackflip
TripleBackflip,
TooManyBackflips,
GoodLand,
GreatLand,
PerfectLand
}
This file is autoloaded via the AutoLoad tab in Project Settings, with the name Skillmove
and the Global Variable checkbox enabled.
In a scene that’s loaded later in the execution of the game, I have this line of code:
func _process(_delta):
var backflip_enum = Skillmove.Skill.Backflip
which throws this error:
Invalid get index 'Skill' (on base: 'Node').
I have followed all the instructions for using player singletons here and code executed elsewhere that utilizes this enum appears to work fine; why is this happening?
That all seems correct to me. So, you’re only having an issue with this enum
in a single scene? Is there something unique about that scene that could point to the problem?
jgodfrey | 2023-02-05 00:19
Nothing, except that it’s part of a scene that’s instanced later instead of loaded at launch.
I can make it work if I do the following:
const SkillMoveType = preload("res://skill_move.gd").Skill
func _process(_delta):
var backflip_enum = SkillMoveType.Backflip
… however this defeats the purpose of preloading the script in the first place.
magicwings | 2023-02-05 00:31
Test run it by adding a dummy scene to the tree and
func _ready():
var test = Skillmove.Backflip
Also double check SkillMove
vs Skillmove
in the name of the autoload symbol.
LeslieS | 2023-02-05 00:42