0 votes

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.

Godot version 3.5.1.stable.mono.official [6fed1ffa3]
in Engine by (31 points)

1 Answer

+1 vote
Best answer

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/[email protected]#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.

https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/c_sharp_differences.html

by (2,017 points)
selected by

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

Try using 0 instead of OK.

This one has worked properly! Thank you.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.