What, Why and When should it be used?
I was studying some example,
platform.Material = Enum.Material.Neon
why not?
platform.Material = “Neon”
much appreciated.
What, Why and When should it be used?
I was studying some example,
platform.Material = Enum.Material.Neon
why not?
platform.Material = “Neon”
much appreciated.
Enums are literally enumerated values. They contain data (i.e 1938193919) that would be insane and stupid for people to remember individually, instead being referred to in scripts as Enum.KeyCode.A, just say, but when indexed by those scripts once run, return the correct value.
It’s often optimal for performance and other factors to use things like seemingly random, long numbers instead of just “Neon”.
All three ways work btw, you can set a material of the part using the enum, the number Id, or string! If you ever want to store an enum you can store it with a string like this
Enum.Material.Neon.Name
Example
local material = Part.Material.Name
game.Workspace.Baseplate.Material = material
so does it mean i can totally ignore enum in my roblox coding journey and just use part.material = “Neon”
if i prefer? ( am i missing out on anything? )
thanks!
That is correct, generally the main reason I use enum is so I don’t mess up. (Cause auto correct)
Although it is still something to look into in the future
Enum usually better than plain strings, because you dont have to know the correct capitalisation
I’ve used Enums since their will never be miscommunication with what behavior I expect. Basically as @bt5191 mentioned in how Enums just are a way to give a human readable version of an ideal system that programmers should use. It basically ensures that their will be no confusion during runtime with what value, of a Base Part’s material in this case, should be set to.
Enums are short for Enumerations, In programming we use Enumerations as some sort of shortcut. Or at least I do. These Enumerations can hold integer values and certain properties that you can use to address it. I find that there isn’t much of a difference using a string, But I also find using enums groups together alot of unique data types and makes you seem more experienced. It’s like a table, With data. But its up to you if you want to use that or not.