K
Kululu17
Guest
Hi All,
I was hoping someone could explain briefly how enums are useful. I've read the manual, and I think I understand HOW to use them, but I just don't get WHY to use them. Here is an example, where I thought they might be useful, but maybe I don't understand their functionality.
I am developing an AI routine for some NPCs, and I thought it would be useful to assign them states to define what they should be doing, so for example camping, exploring, building. I could assign a variable that keeps track of the state, either by assigning it a number, or a string to define the state, and then based on the state, assign behaviors. So either:
NPC_State = 0 //and I know this is camping
or
NPC_State = "camping" //which is clear, and can be shown with the draw command for debugging, but requires a little more work to increment (for the first example, I could switch states by just using NPC_State +=1, here I would have to use some if statements to check the strings.)
or I could use enums, where I define NPC_States with camping, exploring, building, and then I could use
NPC_State = NPC_States.camping // which would equal 0
But I can no longer get the text out of it for debugging like in the second method where I use strings. If I show the value for this, I simply get "0". So it works, but the end result is just like the first example, where I use a number only. So it seems like extra code, but no benefits.
What am I missing here?
Thanks!
I was hoping someone could explain briefly how enums are useful. I've read the manual, and I think I understand HOW to use them, but I just don't get WHY to use them. Here is an example, where I thought they might be useful, but maybe I don't understand their functionality.
I am developing an AI routine for some NPCs, and I thought it would be useful to assign them states to define what they should be doing, so for example camping, exploring, building. I could assign a variable that keeps track of the state, either by assigning it a number, or a string to define the state, and then based on the state, assign behaviors. So either:
NPC_State = 0 //and I know this is camping
or
NPC_State = "camping" //which is clear, and can be shown with the draw command for debugging, but requires a little more work to increment (for the first example, I could switch states by just using NPC_State +=1, here I would have to use some if statements to check the strings.)
or I could use enums, where I define NPC_States with camping, exploring, building, and then I could use
NPC_State = NPC_States.camping // which would equal 0
But I can no longer get the text out of it for debugging like in the second method where I use strings. If I show the value for this, I simply get "0". So it works, but the end result is just like the first example, where I use a number only. So it seems like extra code, but no benefits.
What am I missing here?
Thanks!