Advertisement

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

Started by January 30, 2013 10:53 PM
1 comment, last by Mind Calamity 11 years, 9 months ago

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;
public:
	GameObject(uint32 id, String name, bool isStatic = false);
	int			addRef();
	int			release();
	
protected:
	~GameObject();
	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.

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.

Regards,

Andreas

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

Advertisement

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.

This topic is closed to new replies.

Advertisement