Time for action – Using enums
That's all well and good, but how do we use them? Let's set one up in our AwesomeActor
class.
Add the enum below our class line.
enum EAltitude { ALT_Underground, ALT_Surface, ALT_Sky, ALT_Space, };
The E isn't necessary, but it helps to follow standard guidelines to make things easier to read.
Now we need to declare a variable as that enum type. This is similar to declaring other variables.
var EAltitude Altitude;
Now we have a variable,
Altitude
, that's been declared as the enum typeEAltitude
. Enums default to the first value in the list, so in this case it would beALT_Underground
. Let's see if we can change that in ourPostBeginPlay
function.function PostBeginPlay() { Altitude = ALT_Sky; 'log("Altitude:" @ Altitude); }
Now our class should look like this:
class AwesomeActor extends Actor placeable; enum EAltitude { ALT_Underground, ALT_Surface, ALT_Sky, ALT_Space, }; var EAltitude Altitude; function PostBeginPlay...