i use CScriptHandle like this
CScriptHandle handle;
asIScriptObject *obj = Npcs[id]->scriptObject->object;
handle.opAssign(obj, Npcs[id]->scriptObject->type->GetTypeId());
obj->Release();
return handle;
script
TestShip @npc = cast<TestShip@>(AI.GetNpcScriptHandle(second.id));
if(npc is null)
dbg("FAIL!");
first question:
asIScriptObject stored in CScriptHandle is already created way before being used by CScriptHandle.
i continuously use asIScriptObject to find which script object is associated with npc.
i dont get the call obj->Release(); (without it, Kept by application error)
if CScriptHandle holds a ref wont it be released when it goes out of scope, why do i need to call release on my precious object?
second question:
TestShip class is inherited from NpcShip
so when i cast it like this
NpcShip @npc = cast<NpcShip@>(AI.GetNpcScriptHandle(second.id));
@npc is always null, it cant cast it.
i am assuming this expected behaviour.
if so, how should i achieve this cast? (very important since i cant really know object type, only its base class)
Thank you.