void Spell(Spell& spell, Character& ast, Character& trg){
Party @part=ast.GetParty();
for (int i = 0; i<part.GetEnemies(); i++){
Character &chara=cast<Character>(part.GetEnemy(i));
@chara=null;
}
@part=null;
}
void Spell(Spell& spell, Character& ast, Character& trg){
for (int i = 0; i<ast.party.GetEnemies(); i++){
Character @handle=cast<Character>(ast.party.GetEnemy(0));
int dmg = ast.Stat("Mag").VECI2().y + spell.Stat("Power").VECI2().x;
dmg = dmg * (265 - handle.Stat("Spr").VECI2().y) / 4;
dmg = dmg * spell.Stat("Power").VECI2().x / 256;
dmg = dmg * (Random(0, 32) + 240) / 256;
dmg = Mul(dmg, (handle.Res(spell.Stat("Element").ST()).FT()));
dmg = Mul(dmg, (((handle.Status("Shell").VECI().z>0) ? ShellMod : 1)));
handle.ReceiveDamage(ast, dmg);
}
}
First codebox won't complain but crashes only if that cast exists, the crash occurs only on second run or exiting application.
Will complain about nullpointer access on dmg = dmg * (265 - handle.Stat("Spr").VECI2().y) / 4;
and crash the program if I run the function again or if I exit the application, no ability to trace it properly.
party is registered like
int Party::GetCharacters(){ return m_chars.elms(); }
asIScriptObject *Party::GetCharacter(int i){ return m_chars[i].GetController(); }
BaseEntity *Party::InsertCharacter(){ return &m_chars.New(); }
int Party::GetEnemies(){ return m_enemies.elms(); }
asIScriptObject *Party::GetEnemy(int i){ return m_enemies[i].GetController(); }
BaseEntity *Party::InsertEnemy(){ return &m_enemies.New(); }
void Party::Register(CScriptMgr &m){
// Registering the class method
MYASSERT(m.RegClass<Party>("Party", asOBJ_REF|asOBJ_NOCOUNT));
MYASSERT(m.RegClassMethod("Party", "int GetCharacters()", asMETHOD(Party, GetCharacters)));
MYASSERT(m.RegClassMethod("Party", "IController @GetCharacter(int i)", asMETHOD(Party, GetCharacter)));
MYASSERT(m.RegClassMethod("Party", "BaseEntity &InsertCharacter()", asMETHOD(Party, InsertCharacter)));
MYASSERT(m.RegClassMethod("Party", "int GetEnemies()", asMETHOD(Party, GetEnemies)));
MYASSERT(m.RegClassMethod("Party", "IController @GetEnemy(int i)", asMETHOD(Party, GetEnemy)));
MYASSERT(m.RegClassMethod("Party", "BaseEntity &InsertEnemy()", asMETHOD(Party, InsertEnemy)));
}
Character is extending in angelscript like
class Character : IController
{
Character(){}
Character(BaseEntity @obj)
{
@o = obj;
SetSpells();
}
BaseEntity @o;
}
and IController is registered through C++ by
MYASSERT(m.GetEngine()->RegisterInterface("IController") >= 0);
so my question would be, any ideas what I am doing wrong? do I have to register it in some special way to extend and cast the object from IController to Character?
or is it the Get functions from party that is wrong? eg I am using asIScriptObject as return type.