Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | arnath |
Is it possible to use enum values as dictionary keys in GDScript? I have some code that does the following to setup directional movement. However, when I try to access a value in the dictionary, I get the error “Invalid get index ‘RIGHT’ (on base: ‘int’).” Is this just not allowed? Thanks!
enum Direction {
RIGHT,
LEFT,
UP,
DOWN
}
var movementVectors = {
Direction.RIGHT: Vector2.RIGHT,
Direction.LEFT: Vector2.LEFT,
Direction.UP: Vector2.UP,
Direction.DOWN: Vector2.DOWN
}
var direction = Direction.RIGHT
# Gives me the error Invalid get index 'RIGHT' (on base: 'int').
var movementVector = movementVectors[direction]