Original Post
🔒 Locked
Enumerations?
Advertisement
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 :)
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 :)
AngelScript still lacks support for enums. One day I'll implement it, but not now.
My suggestion is that you do it like this:
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.
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.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement