I’m writing a script which the user configures in a config script.
In one of the configuration fields, the user is asked to provide a font.
This is how it’s defined.
local font = Enum.Font.Gotham
In my main script, I’m trying to validate that the font variable is a Font. If the variable isn’t a font it sets it to a different font. However, when calling typeof on the value it just displays as EnumItem.
Is there a way I can detect what type of item the variable is?
E.G typeof(font) -> EnumItem.Font(the actual typeof returns EnumItem as described above).
typeof is used for determining what type of thing the variable is. So when you called it since “Enum.Font.Gotham” is a type of EnumItem, it printed that out.
whoops sorry, my mistake I was thinking properly for the printing part.
Then you could just manipulate the string to get the text between the periods, Font
And to convert this to the “Font” Enum, you could just do
thisEnum = Enum["Font"]
Of course “Font” would be replaced with the text between the periods, but this should work as a way to get the higher level Enum.
Here’s a code example I made:
local lowerLevelEnum = Enum.Font.Gotham
function GetHighestLevelEnum(lower)
lower = tostring(lower)
local FirstPeriodIndex = string.find(lower,".",1,true)
local SecondPeriodIndex = string.find(lower,".",FirstPeriodIndex+1,true)
local UpperLevelEnum = string.sub(lower,FirstPeriodIndex+1,SecondPeriodIndex-1)
return Enum[UpperLevelEnum]
end
local UpperLevelEnum = GetHighestLevelEnum(lowerLevelEnum) --> Enum.Font