Enumerations (_E
)🔗
An enumeration (or enum) is a set of named integer constants. That is to say, a list of names that are associated with numbers. Enumerations are used instead of just numbers ("magic numbers") to make the code more readable and maintainable.
Internal enumerations are stored in the global _E
table. Each enumeration is
grouped under its own sub-table.
Your own enumerations🔗
You could (and should) implement enumerations yourself when you have a set of constants that are related to each other. For example, if you have a set of roles in your game, you could define an enumeration for them:
In this example ROLES.ADMIN
is an enumeration that represents the admin role.
It's immediately clear what role is checked for, without having to look at the
rest of the code.
In this example 1
is a "magic number" that represents the admin role. This
is bad because it's not clear what 1
means without diving into what the
client:DoRestrictedThing()
function does, and then trying to figure out
which role you think that function should be restricted to.
Enumeration Types
- ACTIVATION_TYPE
- ACTIVITY
- AI_CLASS
- AUTO_RESIZE
- BLOOD_COLOR
- BUTTON
- CHAT_MESSAGE_MODE
- COLLIDE_TYPE
- COLLISION_GROUP
- CONTENTS
- CULL_MODE
- CURSOR
- DAMAGE_TYPE
- DOCK_TYPE
- EDICT_FLAG
- ENGINE_FLAG
- ENTITY_EFFECT
- ENTITY_FLAG
- FCVAR
- FILE_WARNING_LEVEL
- FONT_DRAW_TYPE
- FONT_FLAG
- GESTURE_SLOT
- HIT_GROUP
- HUD_PRINT
- INPUT
- KEY_VALUES_PRELOAD_TYPE
- LABEL_ALIGNMENT
- LIFE
- MASK
- MATERIAL_TYPE
- MOVE_COLLIDE
- MOVE_TYPE
- NETWORK_VARIABLE_TYPE
- OBSERVER_MODE
- PANEL_ALIGNMENT
- PIN_CORNER
- PLAYER_ANIMATION
- PLAYER_ANIMATION_EVENT
- PLAY_SOUND_FLAG
- RENDER_EFFECTS
- RENDER_MODE
- SEARCH_PATH_ADD_TO
- SHADOW_TYPE
- SHAKE_COMMAND
- SKYBOX_VISIBILITY
- SOLID
- SOLID_FLAG
- SOUND_CHANNEL
- SOUND_LEVEL
- STENCIL_COMPARISON_FUNCTION
- STENCIL_OPERATION
- SURFACE
- SURFACE_FEATURE
- USE_TYPE
- VGUI_PANEL