#How to get the enum code from the @GlobalScope.Error

1 messages · Page 1 of 1 (latest)

ember eagle
#

Sometimes a method like load() will return an error, I see it in the godot console, but I want to be able to convert it to a string to display to the user in certain instances. Even just "Error code: 3" would do. Does anyone have any idea how to do this?

tidal path
#

enums are technically just integers, so if you print the return value, you will see the number. and if you use error_string(<that number>) you will get the message

ember eagle
#

Thanks so much fro the help. First I should mention that I'm using 3.5 (I only put that in the tag, sorry). It doesn't look like error_string is a method. But I'm unable to get the number in my own code the first place. I think I might be a little confused actually with how load() works in terms of errors. The code below is a simplification of what I'm trying to do.

imported_scene = load(file)

if imported_scene:
  # Do something
else:
  emit_signal("display_message", "Error: " + imported_scene as String)

If there's an issue with the file I'm trying to load, the console gives me an error from the Enums. But the return value from load() is actually null, not an error enum, which is why trying to render it as a string gives another error. Following the first error to the engine code (https://github.com/godotengine/godot/blob/6c814135b69d4e703956bacc2073b4b179ff5a00/core/io/resource_loader.cpp#L206) shows me that the error is being generated from the ResourceFormatLoader in this case, but I don't know how to access that class in my code. I'm not sure if there is a GlobalScope error stored somewhere that I can draw from or not. Hopefully this makes sense

GitHub

Godot Engine – Multi-platform 2D and 3D game engine - godotengine/godot

tidal path
#

ah yes 3.x does not have that

#

missed the tag

tidal path
#

not sure which error you want out of this though. you can check if the resource exists() though

ember eagle
#

So in this case, this is loading addons/mods for the app, the addon I created had a cyclical dependency which triggered a parse error. So I was hoping to be able to give any future addon devs a more useful error message than just "error" in case they made the same mistake as me since they won't have access to the console on the main app. Maybe it's overkill, but it would be nice to be able to figure out

tidal path
#

yeah not really possible. we couldn't do it either with the mod loader. that's just stuff that needs to be nailed down by them while in development mode. and the application logs will also contain those messages

ember eagle
#

Oh that's good to know, thank so much for your help

#

What are you working on that also has mods? I'm curious

#

(if you don't mind sharing)

tidal path
#

the mod loader itself 😅

ember eagle
#

haha nice

tidal path
#

we put it in dome keeper, brotato and windowkill with the devs

ember eagle
#

Very cool !

tidal path
ember eagle
#

Ah awesome thank you, I wish I had found this earlier before I got deep into making my own 😅 I'll definitely take a look to see if I can get idea for improvements on my code

tidal path
#

feel free to @ me for related questions 😉