Raised This Month: $443 Target: $400
 110% 

Get amount of rows in enum


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SomePanns
Senior Member
Join Date: Dec 2013
Old 05-25-2016 , 13:17   Get amount of rows in enum
Reply With Quote #1

So, I'm trying to figure out how to count the amount of "rows" there's in a specific enum.

For example:
Code:
enum EnumRows
{
VAR1=0,
VAR2,
VAR3,
VAR4
};
In this case, there are 4 "rows" in the enum, but how would I count that with a function?
SomePanns is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 05-25-2016 , 13:50   Re: Get amount of rows in enum
Reply With Quote #2

Assuming that the enum is sequential you can do this, otherwise i don't think there is.

Code:
#include <sourcemod>

enum EnumRows
{
	VAR1=0,
	VAR2,
	VAR3,
	VAR4,
	COUNT
};

public void OnPluginStart()
{
	int rows = view_as<int>(COUNT - VAR1);
	PrintToServer("%d", rows);
}
__________________
Chaosxk is offline
Deathknife
Senior Member
Join Date: Aug 2014
Old 05-25-2016 , 15:12   Re: Get amount of rows in enum
Reply With Quote #3

PHP Code:
int rows view_as<int>(EnumRows); 
__________________
Deathknife is offline
BAILOPAN
Join Date: Jan 2004
Old 05-25-2016 , 16:34   Re: Get amount of rows in enum
Reply With Quote #4

Using a "Count" or "Total" value at the end is preferred, FWIW.
__________________
egg
BAILOPAN is offline
Reply


Thread Tools
Display Modes

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 18:27.


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