I registered an interface, which I then inherit from in script like this.
class testComponent : IComponent
{
testComponent(Component @component)
{
@self = component;
value = 0.0f;
}
Component @self;
float value;
};
I then create instances of this component in c++ and store a pointer to the asIScriptObject from the testComponent script.
Then I have another script file where I want to use the instances of these components, which I'm doing like this.
#include "testComponent.as"
class testSystem : ISystem
{
testSystem( System @system )
{
@self = system;
}
void update(Entity @entity)
{
asIScriptObject @component = entity.component("testComponent");
testComponent @tc = component;
// This is what I want to be able to do...
tc.value = 1.0f;
}
System @self;
};
I've registered the "component" method, which returns the component's asIScriptObject, like this.
engine->RegisterObjectMethod("Entity", "asIScriptObject @component(const string &in)", asMETHOD(Entity, component), asCALL_THISCALL);
All of it works great except for the "testComponent @tc = component;" line in the testSystem script, which gives the following error.
Can't implicitly convert from 'asIScriptObject@&' to 'testComponent@&'.
I've also tried using cast as well, but still the same error. How do I cast the asIScriptObject back to the original script object that created it so I can use that object in script?