AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Get amount of rows in enum (https://forums.alliedmods.net/showthread.php?t=283109)

SomePanns 05-25-2016 13:17

Get amount of rows in enum
 
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?

Chaosxk 05-25-2016 13:50

Re: Get amount of rows in enum
 
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);
}


Deathknife 05-25-2016 15:12

Re: Get amount of rows in enum
 
PHP Code:

int rows view_as<int>(EnumRows); 


BAILOPAN 05-25-2016 16:34

Re: Get amount of rows in enum
 
Using a "Count" or "Total" value at the end is preferred, FWIW.


All times are GMT -4. The time now is 00:34.

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