Enumerations shown as text.

Discussions about Coding and Scripting
Post Reply
UTX
Skilled
Posts: 214
Joined: Fri Aug 28, 2015 3:39 am

Enumerations shown as text.

Post by UTX »

I need to shown the enumerations as text, is that possible?

Example:
I declare
Var Enum Example
{
Something,
Something else,
Something different
} En_Example;

And then I use something like broadcastmessage (En_Example);

Alright, that will show the number, say if En_Example is Something then it's going to broadcast a zero, but I want it to broadcast "Something", how can I do this?
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Enumerations shown as text.

Post by Higor »

I remember seeing a function that prints the string representation of an enumeration within code, but it was UE3 or Unreal227... I could totally implement this in XC_Engine.
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Enumerations shown as text.

Post by Barbie »

Code: Select all

native static final function name GetEnum( object E, int i );
(declared in Object) will do that.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Wormbo
Adept
Posts: 258
Joined: Sat Aug 24, 2013 6:04 pm
Contact:

Re: Enumerations shown as text.

Post by Wormbo »

They way to use it may be a little odd. Remember that enum values are just numbers, so you can plug them into any parameter of types byte or int. That first parameter, however, expects the object representing enum declaration itself. (It's just a standard object literal of type Enum, like the Class, Texture or Sound type literals you probably use all over the place.)

Examples: (logging merely serves as example usage of the GetEnum output)

Code: Select all

Log(GetEnum(Enum'EPhysics', 2)); // logs "PHYS_Falling"
Log(GetEnum(Enum'EDrawType', class'Projectile'.default.DrawType)); // should log "DT_Mesh", unless you messed with something you shouldn't mess with
Log(GetEnum(Enum'ENetRole', Role)); // might log e.g. "ROLE_Authority" in offline games
You could also mess up:

Code: Select all

Log(GetEnum(Enum'EPhysics', Level.NetMode)); // would log e.g. "PHYS_Walking" instead of "NM_DedicatedServer" or "PHYS_Falling" instead of "NM_ListenServer"
UTX
Skilled
Posts: 214
Joined: Fri Aug 28, 2015 3:39 am

Re: Enumerations shown as text.

Post by UTX »

Alright, I will try this out and I'll tell you what I get, if all else fails then I'll use an array or something.
Post Reply