Raised This Month: $51 Target: $400
 12% 

[Cast] Enum Const to Integer ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MaSTeR77
New Member
Join Date: Feb 2016
Old 04-19-2019 , 09:25   [Cast] Enum Const to Integer ?
Reply With Quote #1

Hey guy's, can I cast a enum consts to an integer ?

Code:
char g_sMove[128];
Format(g_sMove, sizeof(g_sMove), "%i", MY_CONDITION ? MOVETYPE_NONE : MOVETYPE_WALK); // Get the integer of the conts MOVETYPE_NONE or MOVETYPE_WALK
SetEntityMoveType(client, view_as<MoveType>(StringToInt(g_sMove))); // View_as of the enum MoveType (which contain the constants) with a StringToInt of my format.. -> It is possible??


Thank's !

-> I know a simple if..else of my condition is better than, but I'am pigheaded.
MaSTeR77 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-19-2019 , 10:26   Re: [Cast] Enum Const to Integer ?
Reply With Quote #2

Yes, that compiles fine.

If the enum name starts with a lowercase letter it'll cast implicitly to an integer as well.
__________________
asherkin is offline
MaSTeR77
New Member
Join Date: Feb 2016
Old 04-19-2019 , 10:29   Re: [Cast] Enum Const to Integer ?
Reply With Quote #3

Thank's for the tip !

Have a good day.
MaSTeR77 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode