I'm trying to display an enum at a label. But i can only do so with the integer values.
Is there a possibility to show the enum text instead of the int value?
lstate.Text = String.Format("State: %d",CurrentState); //this i have now
lstate.Text = String.Format("State: %s",CurrentState); //this won't work
Unfortunately there's no direct way in AGS to do this, but you could define a custom specialized function to do it for you:
String GetEnumName(EnumType value)
{
if (value == eValue1) return "Value1";
if (value == eValue2) return "Value2";
if (value == eValue3) return "Value3";
}
// ...
lstate.Text = String.Format("State: %s", GetEnumName(CurrentState));
*Edited:
Sorry if this is obvious but, why not use a simple string:
string CurrentState;
CurrentState = "Poisoned";
Label.Text = CurrentState;
Quote
show the enum text instead of the int value.
What you're referring to when you say 'text', is actually like a (int) variable.
enum Days {monday, tuesday, wednesday};
Days CurrentDay;
CurrentDay = monday;
//is the same as:
CurrentDay = 0;
Ok thanks a lot guys!
Yeah I know its like an int, I just thought there might be an easy way to do this.
Well a specialized function is way too complicated and I want to use the enum for convinience reasons.
So I'll just have to note down the numbers instead.
I don't see how "not[ing] down the numbers" is a simpler solution than the one I presented (or indeed why the one I suggested is "complicated" at all)..perhaps if you're only doing this for debugging purposes, that would make a bit more sense..but in any case, at least you got a solution for yourself. ;)
I'm just doing this for debugging reasons, yes. So no reason to blow up the code any further. I'd also have to edit this function everytime i add a state - so this is not really practical.
-thanks anyway monkey.