Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Enum over String (when possible)?

So, some people have told me that some object properties use a string value, some use Enum, and some can use both. But they can't stress it enough that if they have the option of Enum, that i use it over a string. Is this true? They both work the same, so i can't see the difference.

For example:

-- Assuming this is in a text label

script.Parent.Font = Enum.Font.ArialBold

-- Instead of ...

script.Parent.Font = 'ArialBold'

So, it's a little blurry to me since both of these methods work the same, but using a string is just generally shorter. Any good reasons?

3 answers

✓ Accepted answer

When setting you can use either string, Enum, or number.

  • Number is bad, because it's not human readable. Always prefer string/enum to number.

  • String is human readable, but you could have made a typo.

  • Enum is human readable, and should prevent typos. However, it's longer.


However, when you get a value, you "have" to use Enum.

if part.TopSurface == "Smooth" then

That will not work. That's because == first checks that the two things are the same kind of thing. But "Smooth" is a string and TopSurface will be an Enum, so that comparison will always be false.

In that case, you have to use Enums.

1 comment

0

Thanks for the explanation.

The choice is up to you! The two options are the same.

I personally use strings, since I know them perfectly.

One advantage of using 'Enum' is that, if you're typing in Roblox Studio's script editor (or command bar), its intellisense will automatically show you valid properties of "Enum" and then of "Enum.Font"

This discussion is preserved as it was. New answers, comments, and votes are closed.