# Enumerations?

This topic is 4033 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

enum MyEnumType { ALPHA, BETA, GAMMA }; Is it possible to expose this to AS, so I can call a function using a enumed type in a function call?

##### Share on other sites
Hi,

The enums are ints, maybe you can use something like this:

// ...
enum MyEnumType { ALPHA, BETA, GAMMA, NUM_TYPES };

static int s_iTypes[ NUM_TYPES ] = { ALPHA, BETA, GAMMA },

engine->RegisterGlobalProperty( "const int ALPHA", &s_iTypes[ ALPHA ] );
engine->RegisterGlobalProperty( "const int BETA", &s_iTypes[ BETA ] );
engine->RegisterGlobalProperty( "const int GAMMA", &s_iTypes[ GAMMA ] );
// ....

Though surely exists an easy form :)

##### Share on other sites
Never thought of doing it that way! While hacky <BG>, unless Andreas suggests otherwise, I'll use this. Thanks!

//edit: Sorry, silly question: why static?

##### Share on other sites
When register a global property you need place the variable pointer. That's mean the variable must exists while the script ( asIScriptEngine ) exists. I made the vars static for this reason, but you can use class member variables o whatever you want :)

##### Share on other sites
AngelScript still lacks support for enums. One day I'll implement it, but not now.

My suggestion is that you do it like this:

const char *constants ="const int ALPHA = 0;     \n""const int BETA  = 1;     \n""const int GAMMA = 2;     \n""const int NUM_TYPES = 3; \n";engine->AddScriptSection(0, "constants", constants, strlen(constants));engine->AddScriptSection(0, "user script", userScript, strlen(userScript));engine->Build(0);

That is, you declare them in a separate script section. If you wish to get even fancier you can implement support for the #include statement, from the sample in the SDK, and then the script writer can include the constant declarations by himself when he needs them.

##### Share on other sites
Yes, I have full include support working atm :)

That was going to be default way of doing it...I'll try both of your suggestions,a nd see which ends up working the best.

CHeers

1. 1
2. 2
3. 3
frob
15
4. 4
5. 5

• 11
• 20
• 12
• 13
• 14
• ### Forum Statistics

• Total Topics
632146
• Total Posts
3004433

×