Another day, another question about AS. -How do you register a script-side inheritable base class? This triggers an assert failure;
r = engine->RegisterObjectType("Base", sizeof(IBase), asOBJ_SCRIPT_OBJECT); assert( r >= 0 );
I've also tried different combinations of these:
asOBJ_VALUE, asOBJ_POD, asOBJ_APP_CLASS_CDA, asOBJ_SCRIPT_OBJECT
but nothing works when using asOBJ_SCRIPT_OBJECT.
Inheriting from application registered classes?
A script class can't directly inherit from a registered class, though it is possible to fake it.
That's a very interesting read SiCrane, thank you for posting it. Seems like that should work for me but I'll have to look at it more thoroughly before attempting something similar.
Right now I've got another problem though; asCScriptEngine::CallObjectMethod keeps crashing for me from this code:
object.create() returns a valid asIScriptObject* through an interface which MyEnemy inherits from, yet the script never gets past that first line.
edit; Ok, looks like the problem is here instead of the cast:
r = engine->RegisterInterface( "GameObject" ); assert( r >= 0 );
r = engine->RegisterObjectMethod( e_str.c_str(), "GameObject @create(const string ∈)", asFUNCTIONPR(CreateObject, (const std::string &), asIScriptObject *), callConvType); assert( r >= 0 );
[edit2] Changing "GameObject @create" to "void create" is working perfectly, though loss of object reference is a bummer. Am I doing something wrong?
[Edited by - arpeggiodragon on September 18, 2010 9:50:49 AM]
Right now I've got another problem though; asCScriptEngine::CallObjectMethod keeps crashing for me from this code:
//asMyEnemy @e = cast<MyEnemy>( object.create("MyEnemy") );if( e is null ){ error("MyEnemy is null!");}
object.create() returns a valid asIScriptObject* through an interface which MyEnemy inherits from, yet the script never gets past that first line.
edit; Ok, looks like the problem is here instead of the cast:
r = engine->RegisterInterface( "GameObject" ); assert( r >= 0 );
r = engine->RegisterObjectMethod( e_str.c_str(), "GameObject @create(const string ∈)", asFUNCTIONPR(CreateObject, (const std::string &), asIScriptObject *), callConvType); assert( r >= 0 );
[edit2] Changing "GameObject @create" to "void create" is working perfectly, though loss of object reference is a bummer. Am I doing something wrong?
[Edited by - arpeggiodragon on September 18, 2010 9:50:49 AM]
Can you show me how the CreateObject method is implemented?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
Okay, The problem was I didn't reference count them. :\ Thing is there is no place to release the reference so I assumed to not even add them... Anyway, I get a compile error; "No copy operator available." from this line:
How do you define an assignment operator for handles of an interface?
[Edited by - arpeggiodragon on September 21, 2010 2:20:28 AM]
GameObject @go = enemy.create( "MyEnemy" );if( go is null ){ error("GameObject is null");}
How do you define an assignment operator for handles of an interface?
[Edited by - arpeggiodragon on September 21, 2010 2:20:28 AM]
You don't, and should not have to either.
This might be a bug in the library. I'll have to look into it.
Are you sure the bug is with this script part?
This might be a bug in the library. I'll have to look into it.
Are you sure the bug is with this script part?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
I don't know. I'm pretty new at using angelscript interfaces. :P Here's how they are declared:
I just tried casting instead and it works fine though.
//c++r = engine->RegisterInterface( "GameObject" ); assert( r >= 0 );r = engine->RegisterObjectMethod( e_str.c_str(), "GameObject@ create(const string &in)", asFUNCTIONPR(CreateEnemy, (const std::string &), asIScriptObject *), callConvType); assert( r >= 0 );//asclass Enemy : GameObject{ //...}class MyEnemy : Enemy{ MyEnemy(){} MyEnemy(const Vector2 &in pos); void run(){...}}
I just tried casting instead and it works fine though.
Enemy @e = cast<Enemy> ( enemy.create( "MyEnemy" ) ); if( e is null ) { error("Enemy is null"); } MyEnemy @me = cast<MyEnemy>(e); if( me is null ) { error("MyEnemy is null"); }
I've not been able to reproduce the error with "No copy operator available.". Can you reproduce it with a small example that I can debug?
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
Popular Topics
Advertisement