Why use ENUM and State vs a string variable?

Wouldn’t you use less code in the end by just using a string?

ie…
if (state == State.Alive) vs if (state == “Alive”)

What are the benefits of using an enum?

1 Like

enums are handled very efficiently, where as computers handle strings worst of all.

enums do not have to be exclusive either, such as you can have player, enemy, questgiver, alive, lootable etc…

Also its less likely to typeo :slight_smile:

something can therefore be enemy and aiive or enemy and lootable, or an enemy and a questgiver… or go from enemy and alive to enemy and lootable… If you ever played a muck/mush type game, this would be exactly how they define flags in the game (Chownable, Dark, Pickupable etc)

1 Like

Ok, that makes good sense to me. Thanks!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms