🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Enumerations?

Started by
4 comments, last by _Sigma 16 years, 11 months ago
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?
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 :)
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?
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 :)
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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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

This topic is closed to new replies.

Advertisement