|
|
|
|
Reply From: |
Bojidar Marinov |
Currently there are a few ways to do it is:
# Multiple constants
const CORNER_W = 0
const CORNER_NW = 1
const CORNER_NE = 2
const CORNER_E = 3
const CORNER_SE = 4
const CORNER_SW = 5
# Dictionary (mutliline, since it avoids the ugly quotation marks) (thanks @sal_vager)
const CORNER = {
W = 0,
NW = 1,
NE = 2,
E = 3,
SE = 4,
SW = 5
}
# Class (thanks @DriNeo)
class Corner:
const W = 0
#....
# Preload
const Corner = preload("corner.gd") # Assuming it has the same structure to the class above
There is a feature request on github about it though: Add enums to GDScript · Issue #2966 · godotengine/godot · GitHub
You could use a constant dictionary for this.
I.e.
const HEROES = {
"Warrior":0,
"Magician":1,
"Thief":2
}
So HEROES[“Magician”] would return 1
sal_vager | 2016-03-14 11:40
@sal_vager, Thanks for the suggestion, seems like I forgot that this time :). Anyway, added it to the question.
Bojidar Marinov | 2016-03-14 12:58
And what do you think about this ? If it’s bad, feel free to answer.
class Corners:
const W = 0
const NW = 1
const NE = 2
const E = 3
const SE = 4
const SW = 5
DriNeo | 2016-03-14 13:37
It looks like the first and second combined, but I’m going to add it too :)… For others, you can comment to the issue itself if you think you have a very bright idea
Bojidar Marinov | 2016-03-14 14:56
Wow plenty of options here. Thank you,
I like subclass solution, it seems elegant.
Daniel Lewan | 2016-03-14 16:13
I like the use of the class for this, I had read that static variables were not supported so I didn’t want to suggest a class that had to be initialized.
I didn’t realize that constants would work for this, thank you, I’ve learned something today
sal_vager | 2016-03-16 17:42