🎉 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!

Case statement and constants

Started by
4 comments, last by WitchLord 18 years, 9 months ago
As I read the documentation the following code should work, but it complains that the case labels aren't constant. What am I doing wrong? const int TMTS_MSG_INITIALIZE = 0x00000001; const int TMTS_MSG_KEY_DOWN = 0x00000003; const int TMTS_MSG_KEY_UP = 0x00000004; void TMSHandler(int msg,int iParam,double dParam,string &inout sParam,uint8[] &inout vParam) { switch(msg) { case TMTS_MSG_INITIALIZE: break; case TMTS_MSG_KEY_DOWN: break; case TMTS_MSG_KEY_UP: break; } } The errors are: Case expressions must be constants for the three case expressions.
Advertisement
Wasn't this issue covered recently?

edit: Ah, yes. Here it is.
Indeed, this was something that I implemented in version 2.4.0. After the discussion in the thread that doynax mentioned.

What version are using? If you're using the 2.4.0 or even 2.4.1, it is possible that your code falls into a slightly different scenario than what I tested, in which case it would be a bug.

I'll give it a look as soon as I can.

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

Yep,

2.4 takes care of the problem. Thanks for your time.
Another wrinkle. When I register the constant from an external program with:

int var = 16;
ret = engine->RegisterGlobalProperty("const int USER_ACTION_SOUND_BELL",(void *)&var);

I can't use USER_ACTION_SOUND_BELL as a case in a switch. This is not urgent for me, but I thought you may want to be aware.

This is stated in the manual.

The problem is that the compiler cannot determine the value of the constant at compile time, this is why the value can't be used in the case statements.

I will implement a way to register true constants and enums in a future version. These will be usable in the switch case statements.

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

This topic is closed to new replies.

Advertisement