Enum

From Goodblox Wiki
Jump to navigationJump to search

An Enum, or Enumerator, is essentially a value used to represent a string.

This allows the code to be read more easily, and to run more efficiently.

For example, say you were writing a script which added crafting functionality, such as that in an RPG. You would need some method of adding the various stat modifiers together, so that you could accurately create an item based on the materials used.

However, as in most programming languages, you are unable to add strings together (Unless of course you concatenated them, which is a completely different thing)

Therefore, you would need to assign the strings a value, or an enumerator. The example below shows how to do this;


wood = 1

iron = 2

steel = 5


Now that you have assigned the strings a value, you are able to easily manipulate them using basic operators. (+, -,*,/, etc)

Another example of enumerators, is the values assigned to the various brick shapes.

A ball is 0,

A block is 1,

And a cylinder is 2.