Thanks for reply!
My mistake was in misunderstanding work of tojson/parsejson
In singleton named G:
enum RockHolderType {
NO_ROCK = 0,
OBLIGATORY_STAR = 1,
COMET = 2,
BLACK_HOLE = 3,
ROCK = 4,
}
In main code:
func check_result():
for k in [ G.RockHolderType.NO_ROCK,
G.RockHolderType.OBLIGATORY_STAR,
G.RockHolderType.COMET,
G.RockHolderType.BLACK_HOLE,
G.RockHolderType.COMET,
G.RockHolderType.ROCK ]:
print("\nValue k = ", k)
var x = { k = k }
var json = to_json(x)
var s = parse_json(json)
var j = s["k"]
match j:
G.RockHolderType.NO_ROCK:
print ("(NO_ROCK) j = ", j)
G.RockHolderType.ROCK:
print ("(ROCK) j = ", j)
G.RockHolderType.OBLIGATORY_STAR:
print ("(STAR) j = ", j)
G.RockHolderType.COMET:
print ("(COMET) j = ", j)
G.RockHolderType.BLACK_HOLE:
print ("(BLACK_HOLE) j = ", j)
_:
print("NOT IN ENUM j = ", j)
print("But!")
if j == G.RockHolderType.NO_ROCK:
print ("(NO_ROCK) j = ", j)
elif j == G.RockHolderType.ROCK:
print ("(ROCK) j = ", j)
elif j == G.RockHolderType.OBLIGATORY_STAR:
print ("(STAR) j = ", j)
elif j == G.RockHolderType.COMET:
print ("(COMET) j = ", j)
elif j == G.RockHolderType.BLACK_HOLE:
print ("(BLACK_HOLE) j = ", j)
else:
print("else j = ", j)
Result:
Value k = 0
NOT IN ENUM j = 0
But!
(NO_ROCK) j = 0
Value k = 1
NOT IN ENUM j = 1
But!
(STAR) j = 1
Value k = 2
NOT IN ENUM j = 2
But!
(COMET) j = 2
Value k = 3
NOT IN ENUM j = 3
But!
(BLACK_HOLE) j = 3
Value k = 2
NOT IN ENUM j = 2
But!
(COMET) j = 2
Value k = 4
NOT IN ENUM j = 4
But!
(ROCK) j = 4
Looks like wrong behaviour, but actually parsejson returns TYPEREAL value.
When debugging, I can't see the type of j
variable, if it has integer value (no decimal point or something else). Not good:(
P.S. Enums in GDScript is some kind of evil.
for l in G.RockHolderType:
print("\nValue l = ", l, ", typeof(l) == TYPE_STRING is ", typeof(l) == TYPE_STRING)
Result:
Value l = NO_ROCK, typeof(l) == TYPE_STRING is True
Value l = OBLIGATORY_STAR, typeof(l) == TYPE_STRING is True
Value l = COMET, typeof(l) == TYPE_STRING is True
Value l = BLACK_HOLE, typeof(l) == TYPE_STRING is True
Value l = ROCK, typeof(l) == TYPE_STRING is True
IMHO these string values is useless. I don't know how to convert them to origin int