Okay, I am sure like my last "problem" I am totally at fault and simply missing something, but let me lay out this problem. Please note, this is all very preliminary code. I am just trying to rig things up to work, I will clean it all up later.
So, I have a class called "Entity" that will represent an entity in my game world. This could be a monster, a sword, anything that has to interact with the game world on more than a simple geometric level. Currently this class has only a single method, GetId, which returns a long. I register it with Angel like so:
void Entity::RegisterForScripting(asIScriptEngine *engine)
{
int r = engine->RegisterObjectType("Entity", 0, asOBJ_CLASS); assert(r >= 0);
r = engine->RegisterObjectMethod("Entity", "int GetId()", asMETHOD(Entity, GetId), asCALL_THISCALL); assert(r >= 0);
}
Simple enough, right? :)
Now, I have a simple script method that does the following:
void OnLoad(Entity obj)
{
Log("Entity ID: " + obj.GetId());
}
Again, very simple stuff.
I invoke the method using the following (extremely messy/ugly) code block:
asIScriptContext *ctx;
Entity *entity = new Entity();
long eid = entity->GetId(); // returns 0;
ctx = m_ScriptEngine->CreateContext();
int id = m_ScriptEngine->GetFunctionIDByDecl(NULL, "void OnLoad(Entity obj)");
ctx->Prepare(id);
ctx->SetArgObject(0, entity);
id = ctx->Execute();
As you can see from the comment on the third line, calling GetId on that instance of Entity returns 0. This is the correct return. Now, when I invoke the script method GetId returns -33686019. It's as if AngelScript is calling GetId on an uninitialized version of the Entity instance I hand it.
Am I simply missing something here? Should I be using an object handle to the entity, rather than simply passing the object like I am currently?
Matt Holmes[ aka Calefaction ]Wildfire Games - General Programmerhttp://www.wildfiregames.com