Jump to content
  • Advertisement
Sign in to follow this  
Mind Calamity

Can't seem to bind a class - Compile errors.

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I've been struggling with registering/binding my class with AngelScript for the past few days, and I've went over the documentation a fair amount of times, but I haven't figured out the problem. I have a class like this:


class ENGINE_EXPORT GameObject : public Object
	friend class Level;
	GameObject(uint32 id, String name, bool isStatic = false);
	int			addRef();
	int			release();
	Level*	mCreator;

	int mRefCount;


And I'm registering it like this:

void bindGameObject(asIScriptEngine* engine)
	int r;
	r = engine->RegisterObjectType("GameObject", 0, asOBJ_REF);
	r = engine->RegisterObjectBehaviour("GameObject", asBEHAVE_ADDREF, "void f()", asMETHOD(GameObject, addRef), asCALL_THISCALL); assert( r >= 0 );
	r = engine->RegisterObjectBehaviour("GameObject", asBEHAVE_RELEASE, "void f()", asMETHOD(GameObject, release), asCALL_THISCALL); assert( r >= 0 );
	r = engine->RegisterObjectMethod("GameObject", "const string& getName()", asMETHOD(GameObject, getName), asCALL_THISCALL); assert( r >= 0 );



The game objects are created by a class "Level" which is registered like so:

void bindLevel(asIScriptEngine* engine)
	engine->RegisterObjectType("Level", 0, asOBJ_REF | asOBJ_NOHANDLE);

	int r = engine->RegisterObjectMethod("Level", "void createSky()", asMETHOD(Level, createSky), asCALL_THISCALL); assert( r >= 0 );
	r = engine->RegisterObjectMethod("Level", "const string& getName()", asMETHOD(Level, getName), asCALL_THISCALL); assert( r >= 0 );
	//r = engine->RegisterObjectMethod("Level", "bool getGameObject(const string &in, GameObject &out)", asMETHODPR(Level, getGameObject, (const String&, GameObject&), bool), asCALL_THISCALL); assert (r >= 0);
	r = engine->RegisterObjectMethod("Level", "const GameObject @+ getGameObject(const string &in name)", asMETHOD(Level, getGameObject), asCALL_THISCALL); assert( r >= 0 );
	//	int r = engine->RegisterObjectMethod("")


The problem is with the getGameObject function, it's declared on the C++ like this:

// String is just a typedef of std::string.
GameObject* getGameObject(const String& name);


And in my actual script I have this:

void testGet()
	GameObject@ obj = level.getGameObject("CamObj");


But I get "Error Compiling void testGet()".


Any ideas as to where my problem is ? (Sorry for the spammy code)


BTW - The addRef and release functions are taken from the Game sample, as is the way of registering.

Edited by Mind Calamity

Share this post

Link to post
Share on other sites

It would help if you showed the actual error message that you get. 


From what you shown I can only imagine that the problem is that you've regstered the getGameObject to return a 'const GameObject @', and this cannot be assigned to a non-const handle. 


Either register the method to return the handle without the const, or change the script to declare the variable as const.




Share this post

Link to post
Share on other sites

That was such a stupid mistake on my part. Sorry about that. :)


I tried so many different ways to bind it, and I tried removing "const" on one of them, and I still got the same result, but this time that was the problem. :)


Thanks for the quick reply.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!