I'm trying to pass a handle of a game object to a script function, but its not working properly.
CScriptAny *Object::GetScriptObject()
{
CScriptAny *n = new CScriptAny( scriptManager->GetEngine());
int typeId = scriptManager->GetEngine()->GetTypeIdByDecl("Base_Object_IMP@");
n->Store( pScrObj, typeId);
return n;
}
Base_Object_IMP is the interface that the parent class of all scripted game objects, Base_Object inherit. Each instance store a asIScriptObject returned from the constructor. The function above fails with an access violation and it doesn't seem to be able to find the type id for 'Base_Object'.
I'm trying to cast from the base type to a another child type, like so:
Base_Object @base = null;
Object @obj = find_instance( objPlayer, Player);
if (obj != null)
obj.GetScriptObject().retrieve( @base);
objPlayer_controller @PlayerHandle = cast<objPlayer_controller>( @base);
This is what I'm trying to do:
asIScriptObject -> Base_Object_IMP@ -> Base_Object@ -> objPlayer_controller@ (or any other child type).
Is there a proper way to do this?