# How do I reference an enum from an autoloaded script?

**URL:** <https://forum.godotengine.org/t/how-do-i-reference-an-enum-from-an-autoloaded-script/2412>\
**Category:** Archive\
**Created:** [February 5, 2023, 12:04am UTC](https://forum.godotengine.org/t/how-do-i-reference-an-enum-from-an-autoloaded-script/2412 "2023-02-05T00:04:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [February 5, 2023, 12:04am UTC](https://forum.godotengine.org/t/how-do-i-reference-an-enum-from-an-autoloaded-script/2412/1 "2023-02-05T00:04:23Z")

</div>

| | | |
| --- | --- | --- |
| ℹ | **Attention** | Topic was automatically imported from the old Question2Answer platform. |
| 👤 | **Asked&nbsp;By** | magicwings |

I have a file called `skill_move.gd` that contains the following:

```auto
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:

```auto
func _process(_delta):
	var backflip_enum = Skillmove.Skill.Backflip

```

which throws this error:

```auto
Invalid get index 'Skill' (on base: 'Node').

```

I have followed all the instructions for [using player singletons here](https://docs.godotengine.org/en/stable/tutorials/scripting/singletons_autoload.html) 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:

```auto
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

```auto
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

---

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [February 5, 2023, 6:04pm UTC](https://forum.godotengine.org/t/how-do-i-reference-an-enum-from-an-autoloaded-script/2412/2 "2023-02-05T18:04:50Z")

</div>

| | | |
| --- | --- | --- |
| 👤 | **Reply From:** | Inces |

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 :

```auto
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`
