🎉 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!
Trying to register a const static member variable
In my game, constants are organized by what objects they are used in, so several classes have a bunch of static const int members. I would like to register one such class with AS, and am having trouble getting a pointer to these static const ints to pass to the Register*Property() function.
What's the best way to go about this? Should I use RegisterObjectProperty() or RegisterGlobalProperty(), and how do I send in a pointer?
Thanks.
A static class member is just a global variable, except that it is only visible within the namespace of the class. You'll have to register the property as a global property in AngelScript. You get the pointer of it just as any other variable.
r = engine->RegisterGlobalProperty("const int prop", &MyClass::StaticMember); assert( r >= 0 );
Indeed, that's what I tried:
Here's where the vars are defined in Command:
And here are the errors that occur:
r = engine->RegisterGlobalProperty("const int CMD_EXIT", &Command::CMD_EXIT); assert (r >= 0);
Here's where the vars are defined in Command:
class Command{ ... const static int CMD_UNDEF = 0, CMD_LOOK = 1, CMD_STATUS = 2, CMD_SAY = 3, CMD_EMOTE = 4, CMD_TAKE = 5, CMD_DROP = 6, CMD_INV = 7, CMD_MOVE = 8, CMD_EXIT = 9; ...};
And here are the errors that occur:
1>e:\my documents\my c++\wx_mud_2\wx_mud_2\scriptingengine.h(350) : error C2664: 'asIScriptEngine::RegisterGlobalProperty' : cannot convert parameter 2 from 'const int *__w64 ' to 'void *'1> Conversion loses qualifiers
You can probably just use a const_cast here.
r = engine->RegisterGlobalProperty("const int CMD_EXIT", const_cast<int *>(&Command::CMD_EXIT)); assert (r >= 0);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement