Is there any way to access an enum by index?
#1

The lack of the possibility to loop through enums drives me crazy.
Reply
#2

This....is just..random.
Reply
#3

Eh?
Reply
#4

Yes. Example:
PHP Code:
enum ENUM_NAME
{
    
3,
    
Float:5.2,
    
bool:false
}
ENUM_NAME:0
ENUM_NAME:1
ENUM_NAME:2
for(new 0ENUM_NAME:ENUM_NAMEi++)
    
printf("#%d - %d"iENUM_NAME:i); // prints the INDEX 
Reply
#5

Quote:
Originally Posted by MoroDan
View Post
Yes. Example:
PHP Code:
enum ENUM_NAME
{
    
3,
    
Float:5.2,
    
bool:false
}
ENUM_NAME:0
ENUM_NAME:1
ENUM_NAME:2
for(new 0ENUM_NAME:ENUM_NAMEi++)
    
printf("#%d - %d"iENUM_NAME:i); // prints the INDEX 
Thank you mate.
Reply
#6

Actually it doesn't work.
PickupsList - Dealership:0
will give a warning of "invalid function or declaration".
Reply
#7

I did try, right after the enum:

Code:
enum PickupList
{
	Dealership,
	Rental
}
PickupList - Dealership:0
PickupList - Rental:1
Quote:

error 010: invalid function or declaration

on line "PickupList - Dealership:0"
Reply
#8

That's not supposed to be there. That's just documentation. Comment it or remove it if you want.
Reply
#9

Oh, thank you, got it working.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)