After a HTTP request failure, how do we take that number and get the string equivalent from the Enum, as listed in the documentation?
https://docs.godotengine.org/en/stable/classes/class_httprequest.html#enumerations
After a HTTP request failure, how do we take that number and get the string equivalent from the Enum, as listed in the documentation?
https://docs.godotengine.org/en/stable/classes/class_httprequest.html#enumerations
As far as I know, you would have to do it manually.
For example, you could set up a Dictionary:
const HTTP_REQUEST_RESULT_TEXT: Dictionary = {
HTTPRequest.RESULT_SUCCESS: "SUCCESS",
HTTPRequest.RESULT_CHUNKED_BODY_SIZE_MISMATCH:
"CHUNKED_BODY_SIZE_MISMATCH",
HTTPRequest.RESULT_CANT_CONNECT: "CANT_CONNECT",
...
}
Wow, I feel a little bit surprised that gdscript can't handle describing enum's.
doja2 enums will see some improvements in godot 4.
doja2 Wow, I feel a little bit surprised that gdscript can't handle describing enum's.
Why is it surprising? It's an open-source community-driven project. Features only exist if someone is motivated to implement them. In this case, I suppose no one considered it worthwhile, since the descriptions are in the documentation.
You could submit a proposal for the feature:
https://github.com/godotengine/godot-proposals
DaveTheCoder Why is it surprising?
Reflecting on your question about why I might have had a surprised feeling. I believe I have personally never encountered a programming language where printing the values of enums was not easy, except for perhaps c, although nothing is easy in c. That past experience creates a type of internal assumption that languages can usually do this. Does that help answer your question about why I had a surprised feeling?
You can do it like this:
ENUM_NAME.keys()[enum_val]
But it's not surprising to me, coming from working with C++ for a while.
cybereality ENUM_NAME.keys()[enum_val]
Can you provide an example?
I'm not at home right now. I believe it would be something like this:
var result = 0 # or whatever you get back
var result_string = HTTPRequest.Result.keys()[result]
cybereality I'm not at home right now.
Okay, I won't expect an immediate response.
If I try this:
print_debug(HTTPRequest.Result.keys())
I get the error:
Invalid get index 'Result' (on base: 'GDScriptNativeClass').
That enum is defined here:
https://github.com/godotengine/godot/blob/3.5.1-stable/scene/main/http_request.h
The analogous code works, though, on an enum that I define in my script. That surprised me; I didn't know that enums behaved like Dictionaries. Maybe that only applies to GDScript enums, and not C++ enums?
Maybe there is a way to get the enum somehow. I'm on a Chromebook right now and it's kind of hard to test anything, or even do any research. This machine is so slow.
I did try to find a way to get access to refer to the Result (as in HTTPRequest.Result) object, but I couldn't get it to work. I am pretty noob at this.