0 votes

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?

Godot version 3.5.1
in Engine by (12 points)

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?

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.

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.

1 Answer

0 votes

It is pointless to use autoload for this. You can use any form of static typing.
Option nr 1:
Keep all individual enums inside corresponding classes
Option nr 2:
Create enums class, that will only contain all constant data for other nodes to use or for autocomplecion purposes.

Either way, all You have to do is :

extends Node
class_name skillmove
enum Skill {}

Static node doesn't even need to be loaded as singleton, it simply has to exist anywhere in your filesystem. You refer to it by its class, like var test = skillmove.Skill.Jump

by (8,099 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.