informa
/
1 MIN READ
Blogs

Enumerate! Enumerate!

Enumerations, or enums for short, have the power of descriptiveness that standard strings do while simultaneously retaining the simplicity and combinable nature of integers. This post covers why they are useful, as well as how to use them.

 

Fans of Doctor Who will probably shun me for that titling. What are enumerators, or, more specifically, enums? To put it succinctly, enums are words that are actually numbers. What does this mean? It means that when you write your code you can check for words, but when it gets compiled the compiler takes those words and replaces them with numbers. You may wonder why to bother with such a thing. It's pretty simple really. Enums allow you to have readable code while keeping a small overhead. They are better than character strings because they are smaller, and they are better than just plain integers because they can be rearranged, and are much more readable. Below is an example enum use:

enum Skills = {Heal,               Harm,               Strengthen,               Weaken,               BuffArmor,               CorrodeArmor,               EnhanceAccuracy,               DegradeAccuracy,               PushPull}
public void ApplySkill(Skills skillType, float amount){    switch (skillType) {    case Skills.Heal:        health += amount;        break;    case Skills.Harm:        health -= amount;        break;    .    .    .    }}

You could just use integers, but it would be hard to keep track of which number represented what over a larger code-base. And while you could use strings, capitalization is not your friend, not only that, but professionally enums are the accepted solution as it will reduce the memory footprint and compiled file size.

 

Latest Jobs

IO Interactive

Hybrid (Malmö, Sweden)
3.02.23
Gameplay Director (Project Fantasy)

Arizona State University

Los Angeles, CA, USA
2.27.23
Assistant Professor of XR Technologies

IO Interactive

Hybrid (Copenhagen, Denmark)
3.02.23
Animation Tech Programmer

Purdue University

West Lafayette, IN, USA
3.02.23
Assistant Professor in Game Design and Development
More Jobs   

CONNECT WITH US

Explore the
Advertise with
Follow us

Game Developer Job Board

Game Developer

@gamedevdotcom

Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Browse
Advertise with

Game Developer

Engage game professionals and drive sales using an array of Game Developer media solutions to meet your objectives.

Learn More
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more