Gamasutra: The Art & Business of Making Gamesspacer
View All     RSS
February 10, 2016
arrowPress Releases
February 10, 2016
PR Newswire
View All
View All     Submit Event






If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 
Enumerate! Enumerate!
by Robert Plante on 02/11/13 12:54:00 am

The following blog post, unless otherwise noted, was written by a member of Gamasutra’s community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.

 

 

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.

 


Related Jobs

Visionary VR
Visionary VR — Los Angeles, California, United States
[02.10.16]

Senior Unity Engineer
Sony Computer Entertainment Europe
Sony Computer Entertainment Europe — Manchester, England, United Kingdom
[02.10.16]

Experienced Gameplay Programmer
Sony Computer Entertainment Europe
Sony Computer Entertainment Europe — Manchester, England, United Kingdom
[02.10.16]

Experienced Game Designer-Systems
Insomniac Games
Insomniac Games — Burbank , California, United States
[02.09.16]

Senior Engine Programmer





Loading Comments

loader image