Equivalent of "OK" and other codes in C#?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Y_VRN

I’ve been getting my hands on Godot Mono for about a few days, and it’s truly fun trying C# even if I receive so many errors on each new line I write. What I want to do though is load a directory for a complex dialogue system. Unfortunately, I can’t seem to find the best docs/API reference site for Godot Mono (some sites use GDScript code samples instead of C#… :I ).

I’m stuck on what to do if the directory specified doesn’t exist or something else happened. In GDScript, I believe it would be written like this:

var Is_Dir_Loaded = My_Directory.open("res://something") == OK

But the OK code? I have no clue what it is in C#. What is the equivalent “word” for this? Also, if there is a right solution, will it also apply to other error codes? Thanks.

:bust_in_silhouette: Reply From: magicalogic

OK is just a constant with a value of zero meaning no error. All other error codes have values greater than zero. You can see all of them here. https://docs.godotengine.org/en/stable/classes/class_@globalscope.html#class-globalscope-constant-ok
This is in gdscript though. To change them to C#, replace the ERR_* with Error.*.
An example, ERR_FILE_NOT_FOUND becomes Error.FILE_NOT_FOUND.
See more API differences between gdscript an C# here.


I’m still getting a build error, which says " ‘Error’ does not contain a definition" for any error I use, even OK. I also tried only putting OK, yet to no avail. I’m using Godot.Directory instead of System.IO.Directory. Am I doing something wrong?

Definition_Dir.Open("res://Assets/Definitions/Dialogs") == OK

Y_VRN | 2022-11-22 12:35

Try using 0 instead of OK.

magicalogic | 2022-11-22 16:37

This one has worked properly! Thank you.

Y_VRN | 2022-11-23 13:54