const variables VS enumerators

09/23/2011 21:57 BaussHacker#1
What is better to use?

It's Conquer Related, because it's for my source.

Currently I have been using enumerators, except for packetids and mapids they are const variables.
09/23/2011 22:00 12tails#2
hmmm i use const variables for some things and enum's for others... i've took the example of EO Source....
it's a good resource project :]

example:
Code:
        const int ITEMSORT_INVALID = -1;
        const int ITEMSORT_EXPEND = 0;
        const int ITEMSORT_HELMET = 1;
        const int ITEMSORT_NECKLACE = 2;
        const int ITEMSORT_ARMOR = 3;
        const int ITEMSORT_WEAPON1 = 4;
        const int ITEMSORT_WEAPON2 = 5;
        const int ITEMSORT_SHIELD = 6;
        const int ITEMSORT_RING = 7;
        const int ITEMSORT_SHOES = 8;
        const int ITEMSORT_OTHER = 9;
09/23/2011 22:02 BaussHacker#3
Quote:
Originally Posted by 12tails View Post
hmmm i use const variables for some things and enum's for others... i've took the example of EO Source....
it's a good resource project :]
Yeah I mean, where should I use what. :)
09/23/2011 22:04 Mr_PoP#4
Quote:
Originally Posted by BaussHacker View Post
Yeah I mean, where should I use what. :)
when you don't need a magic numbers everywhere lol
09/23/2011 22:05 Korvacs#5
Enums imo, you can do more useful things with enums, a constant is just a constant, not much you can do with it.
09/23/2011 22:06 BaussHacker#6
Quote:
Originally Posted by Mr_PoP View Post
when you don't need a magic numbers everywhere lol
Care to explain? :D
09/23/2011 22:09 12tails#7
i would say to use an enum when you would struct something like ItemInfo/UserData
and use Get/Set methods to control the variables as you wish... doing this way you would prevent an major error doing a mistake or something like while ur coding...

example:
Code:
class UserData
{
      private uint uiId;
      private string szName;
      public const int MAX_LEVEL = 140;//ex to use a const

      enum EntityVariable { Id, Name }//ex to use a enum

      public uint GetInt(EntityVariable evObject) 
      { 
            switch (evObject)
            {
                  case EntityVariable.Id:
                        return uiId;
            }
      }

      public string GetStr(EntityVariable evObject) 
      { 
            switch (evObject)
            {
                  case EntityVariable.Name:
                        return szName;
            }
      }

      public void SetStr(EntityVariable evObject, string szValue) 
      { 
            switch (evObject)
            {
                  case EntityVariable.Name:
                        szName = szValue;
                        //TODO: Actions after change name here
                        break;
            }
      }
}
09/24/2011 05:38 _tao4229_#8
[Only registered and activated users can see links. Click Here To Register...]


each individual ITEM is then an enumerator.
please.
09/24/2011 11:12 BaussHacker#9
Quote:
Originally Posted by _tao4229_ View Post
[Only registered and activated users can see links. Click Here To Register...]


each individual ITEM is then an enumerator.
please.
LOL