Enumerations

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

SuperDre

New Member
May 6, 2002
254
0
0
Helmond.nl
www.superteam.tk
Hi,

I was wondering how can you use enumerations? With that I mean like TypeCasting, comparing/setting to/from an integer.

ex.
Code:
enum EColor
{
  colRed,
  colGreen,
  colBlue
};

var int       i;
var EColor  eColor;

Code:
 i=eColor;
 switch(i)
 {
  case colRed: doSomething; break;
  case colBlue: doSomething; break;
  case colGreen: doSomething; break;
 };
 
Last edited by a moderator:

Mychaeel

New Member
Just try it. Much faster than writing a question and waiting for an answer.

What you can't do, anyway, is casting a number to an enum type. Everything else is quite intuitive.

And please use [code]...[/code] tags when you quote code in order to preserve its indentation. Thanks.
 
Last edited:

SuperDre

New Member
May 6, 2002
254
0
0
Helmond.nl
www.superteam.tk
Sorry for the missing code tags, it's been awhile since I posted.. :eek:

Damn I figured something out... When typecasting you have to put the Enum in front of it...

Code:
var int  i;
var EColor  eCLR;

  i=int(EColor.colRed)     //This works
  i=int(colRed)              //This gives an error

So there is no way to do (see following)?

Code:
var int  i;
var EColor  eCLR;

  i=2;
  eCLR=EColor(i);  //1.
  eCLR=ord(i);      // don't know if such a function exists

Otherwise it's just better to use consts... (That's what I'm using now, but I would like Enums better, they keep the code more neat.. (I'm used to VB..)