Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Mind Calamity   Members   -  Reputation: 134

Like
0Likes
Like

Posted 30 January 2013 - 04:53 PM

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.


Edited by Mind Calamity, 30 January 2013 - 04:54 PM.


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3220

Like
0Likes
Like

Posted 31 January 2013 - 07:37 AM

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

#3 Mind Calamity   Members   -  Reputation: 134

Like
0Likes
Like

Posted 31 January 2013 - 03:06 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS