[Extension] Enums in blocks!

Ever wanted to use Enumerations in blocks? No? Well, now you can!


Once again introducing an extension, this time it’s enums!

I was working on an extension and realized how useful enumerations would be to use in blocks. So I put this extension together in about 10 minutes.

There’s not a lot to it, there’s a single block and it’s used to create members.
If you wish to use enums in a method, set the argument type to number.

Wow, such block!

5 Likes

what is an enumeration?

1 Like

According to Google (this will sound very professional)

It is a noun meaning “the action of mentioning a number of things at once.”
Formally it means “the action of establishing the number of something.”

1 Like

yes great extenstion @randomuser i dont know how to explain it

1 Like

its technicaly a list
but its for extensions

1 Like

Not exactly, It can be applied anywhere

Oh, that’s kind of like a list of numbers, where you can assign every number to a name.
For example, writing an enumeration looks something like this:
(javascript)

enum MyEnum {
// Name, Value (optional)
    Dog = 1,
    Cat = 2
    ...
}

This means that for constants, you can replace them with Enums to make them look tidier.
For example, say you want to choose between a direction, ‘left’ or ‘right’.

Now, the initial idea may be to use strings or numbers.
(left = “left” or 0, and right = “right” or 1)

if (direction == "left") {
    ...
}

or

if (direction == 0) {
    ...
}

But instead, you can define enums to make this a lot nicer.

enum Direction {
    Left, // enums are incremental, so this will be automatically set to 0
    Right // the next member will be +1, so 1
}

if (direction == Direction.Left) {
    ...
}

It’s also important to mention that members of enumerations are, well - numbers. Each member is assigned a value, which is auto-increment, or you can define values yourself.

enum MyEnum {
    Foo, // 0
    Bar // 1
}

console.log(MyEnum.Foo); // Expected output: 0
console.log(MyEnum.Bar == 1); // Expected output: true

P.S, all members must adhere to one scheme. If you’re defining a member with an explicit value (eg. Foo = 2), all other members must have it defined too. You cannot have a mix of implicit and explicit values in you enumerations.

You might also see expressions like Foo = 2 << n; within enums. These are just powers of 2, so the numbers of the members will be exponential. The << operation is a bitwise shift to the left, which means it shifts all of the bits left in a number (eg. 0010 << 1 = 0100)

enum MyEnum {
    Foo = 2 << 0, // 2
    Bar = 2 << 1, // 4
    Baz = 2 << 2 // 8
    ...
}

With my extension, all of the members are stored in one built-in enumeration, but you can add your own members. I hope this cleared something up, if you have more questions just ask!

Further reading / reference

3 Likes

Yes thank you!

1 Like

ahhh yes some code i dont understand

1 Like

Glad this post help you understand this more!
I made this extension mostly for myself, since I needed enums for something I was making so I decided to share it anyway.

1 Like

Do you want me to explain something further? I’d be glad to if it helps!

1 Like

nah that was sarcasm i can understand it