Luau Quick Enum Parsing?

image

I’m trying to create enums, and would like AdminType to be AdminLevels.None & AdminLevels.Admin & AdminLevels.Creator instead of making it type {None: number, Admin: number, Creator: number}. Is there a simple way to do this or do I have to specify that all out?

This is a short and quick example, but it’s starting to get annoying when it’s the 10th enum system I make where I have to write the enums twice to declare them and it adds an extra dependency I have to remember to update if I change the enums or add more later.

1 Like

AdminType has a type of:

{
    None: number,
    Admin: number,
    Creator: number,
}

But, AdminLevels.None only has a type of number.

2 Likes

Is there a way to make it type 0 & 1 & 2 or does it have to be type number?

You can’t explicitly define what number something can be. You can only do that with strings (called string literals).

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.