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

Problem registering an object

Started by
3 comments, last by WitchLord 17 years, 3 months ago
Hi, there! I have a problem registering objects in AngelScript. Suppose I have an object Actor that inherit from Entity2D and I don't want to copy all the methods registration from Entity2D in Actor. So, i've made a method in Entity2D like this: static bool RegisterEntity2D(char *className=NULL) { char _className[100]; if (className != NULL) { strcpy_s(_className, 100, className); } else { strcpy_s(_className, 100, "Entity2D"); if (ScriptMgr::RegisterObjectType(_className, sizeof(Entity2D), asOBJ_CLASS) < 0) return false; } if (ScriptMgr::RegisterObjectMethod(_className, "void SetCollisionColor(uint)",asMETHOD(Entity2D, SetCollisionColor),asCALL_THISCALL) < 0) return false; if (ScriptMgr::RegisterObjectMethod(_className, "void SetCollisionRadius(float)",asMETHOD(Entity2D, SetCollisionRadius),asCALL_THISCALL) < 0) return false; return true; } Then, in Actor I've made something like this: bool Actor::RegisterActor(char *className) { char _className[100]; if (className != NULL) { strcpy_s(_className, 100, className); } else { strcpy_s(_className, 100, "Actor"); if (ScriptMgr::RegisterObjectType(_className, sizeof(Actor), asOBJ_CLASS) < 0) return false; } if (!Entity2D::RegisterEntity2D(className)) { return false; } if (ScriptMgr::RegisterObjectProperty(_className, "int _action",offsetof(Actor, _action)) < 0) return false; if (ScriptMgr::RegisterObjectProperty(_className, "int _state",offsetof(Actor, _state)) < 0) return false; return true; } Here all works ok, but when i've tried to access some methods from Entity2D in an Actor object from AngelScript, it says "Actor (10, 13) : ERR : No matching signatures to...". What is going on? Can I do this kind of registration? Thanks in advance! P.S: This is only an example, i've registered so many properties and methods to put them here.
=====================================Regards,Juan Pablo (McKrackeN) Bettini Psychoban Official Site:http://www.psychoban.comPsychoban on iTunes App Store:http://itunes.apple.com/us/app/psychoban/id378692853?mt=8
Advertisement
I think you're problem is here:

if (!Entity2D::RegisterEntity2D(className)) {    return false;}


You're passing in className to Entity2D, but if I understand you correctly className is actually NULL. You should probably pass in _className instead.

Fixing that problem should make it all work.

I like the way you've done this. Maybe I'll be able to reuse some of these ideas in the AngelScript manager I'm planning on writing.

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

No, I've made a mistake when i copied & pasted the code. I've passed _className instead of className, but it didn´t work.

When I want to register an actor, i call the method without arguments:
	if (!Actor::RegisterActor())		return false;


So className is NULL.

	char _className[100];	if (className != NULL) {		strcpy_s(_className, 100, className);	} else {		strcpy_s(_className, 100, "Actor");		if (ScriptMgr::RegisterObjectType(_className, sizeof(Actor), asOBJ_CLASS) < 0)			return false;	}	if (!Sprite::RegisterSprite(_className)) {		return false;	}		if (ScriptMgr::RegisterObjectProperty(_className, "int _action",offsetof(Actor, _action)) < 0)		return false;	if (ScriptMgr::RegisterObjectProperty(_className, "int _state",offsetof(Actor, _state)) < 0)		return false;	if (ScriptMgr::RegisterObjectProperty(_className, "float _turnReaction",offsetof(Actor, _turnReaction)) < 0)		return false;...}


When I call Sprite::RegisterSprite(_className), it registers all the methods of Sprite class but with Actor as class name:

bool Sprite::RegisterSprite(char *className) {	char _className[100];	if (className != NULL) {		strcpy_s(_className, 100, className);	} else {		strcpy_s(_className, 100, "Sprite");		if (ScriptMgr::RegisterObjectType(_className, sizeof(Sprite), asOBJ_CLASS) < 0)			return false;	}	if (!Shape::RegisterShape(_className))		return false;	if (ScriptMgr::RegisterObjectMethod(_className, "Animation@+ GetAnimation(void)",asMETHOD(Sprite, GetAnimation),asCALL_THISCALL) < 0)		return false;	if (ScriptMgr::RegisterObjectMethod(_className, "void SetAnimation(Animation@+)",asMETHOD(Sprite, SetAnimation),asCALL_THISCALL) < 0)		return false;...}


And so on. I've made this because I didn't want to register all the methods several times for each inheritance (for Entity2D, Sprite, Actor, and all the other classes).

Here is an example of the AngelScript code:
void SetAction(Actor &inout actor, int action, float pointX, float pointY) { 	if (action == ACTOR_ACTION_LOOKAT) {		float x = actor.GetPosX();		float y = actor.GetPosY();        }}


I've tried using &inout, @ and @+. But it's still telling me:

Actor (3, 1) : INFO : Compiling void SetAction(Actor@, int, float, float)
Actor (5, 19) : ERR : No matching signatures to 'GetPosX()'
Actor (6, 19) : ERR : No matching signatures to 'GetPosY()'

Do you see any errors in my code? Could it be that I pass "Actor" as the name of the class but then I've tried to pass the method pointer from it's parent Sprite?

	if (ScriptMgr::RegisterObjectMethod(_className, "Animation@+ GetAnimation(void)",asMETHOD(Sprite, GetAnimation),asCALL_THISCALL) < 0)		return false;


_className = "Actor"
asMETHOD(Sprite, GetAnimation)

=====================================Regards,Juan Pablo (McKrackeN) Bettini Psychoban Official Site:http://www.psychoban.comPsychoban on iTunes App Store:http://itunes.apple.com/us/app/psychoban/id378692853?mt=8
I've found the problem!!! It wasn't regarding to the way I register from the parents of the classes. It was a problem with some methods that hasn't parameters and I've registered them as (for example) "float GetPosX(void)". Changing it to "float GetPosX()" it works well.

Thanks anyway for the help and i'm glad to know that you found the way I register the classes useful.

See you son, and THANKS for the AngelScript. It's great! ;)
=====================================Regards,Juan Pablo (McKrackeN) Bettini Psychoban Official Site:http://www.psychoban.comPsychoban on iTunes App Store:http://itunes.apple.com/us/app/psychoban/id378692853?mt=8
I'm glad you found the problem.

I'll have to take look at registering functions with void parameters. It should have been the same as registering the function with an empty parameter list. This is probably a bug in AngelScript. Thanks for letting me know.

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

This topic is closed to new replies.

Advertisement