0 votes

Hey there,

When scripting in C#, what is the correct syntax to accessing enum values, e.g. ACCESS_USERDATA, ACCESS_FILESYSTEM, etc... ( http://docs.godotengine.org/en/latest/classes/class_filedialog.html#enums )?

in Engine by (20 points)

1 Answer

+2 votes

Nevermind, figured it out myself. It's FileDialog.AccessEnum.Filesystem. There is a gotcha here, because that enum in GDScript is called just Access, but in C# it's AccessEnum. This is because the name Access is already taken by a field in FileDialog. If it weren't taken, the enum would be called just Access. For example in Control, the size flags are accessed as Control.SizeFlag.Fill, etc..., and not Control.SizeFlagEnum.Fill.

This should probably be mentioned in the docs.

by (20 points)

What you can do to figure out what name the enum value names is to give a random value to a variable of the type you want, the see the "Cannot convert bla into Godot.bla" error. The enum name will be that. In my case, I wanted to change the format of an AudioStreamSample. This has enum values. I made a new variable of type AudioStreamSample, the changed its Format to a random integer like so:

AudioStreamSample sample = (AudioStreamSample)ResourceLoader.Load("res://fart");
sample.Format = 3;

Next, an error ocurred:

Cannot convert type 'int' to 'Godot.AudioStreamSample.FormatEnum'

And there you have it. Just change the 3 with Godot.AudioStreamPlayer.FormatEnum.ImaAdpcm

(The last thing is whatever the value is in c# format, so capital letters to replace the underscores)

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.