mysql - System.IndexOutOfRangeException: Index was outside the bounds of the array Database - Game.cs -
it seems thank phil allison has has fixed first issue new error line 246.
if (tamer.digimonlist.length >= 3) { if (tamer.digimonlist[3] == null) qry.add("mercenary3", null); else qry.add("mercenary3", tamer.digimonlist[3].digiid); }
hello there sorta new if can give me decent advice on improving post or me issue appreciated!
the game crashes after loading game error seems on line 245 below
if (tamer.digimonlist[3] == null) qry.add("mercenary3", null); else qry.add("mercenary3", tamer.digimonlist[3].digiid);
the error
system.indexoutofrangeexception: index outside bounds of array. @ digital_world.sqldb.savetamer(client client) in c:\users\digimon master\dropbox\digimon master project\dmofrosty'spost\server\serverbuildingsection\digitalworld\database - game.cs:line 245
the code
character tamer = client.tamer; using (mysqlconnection con = connect()) { query qry = new query(query.querymode.update, "chars", new tuple<string, object>("characterid", tamer.characterid)); qry.add("charmodel", (int)tamer.model); qry.add("charname", tamer.name); qry.add("charlv", tamer.level); qry.add("experience", tamer.exp); qry.add("money", tamer.money); qry.add("partner", tamer.digimonlist[0].digiid); if (tamer.digimonlist[1] == null) qry.add("mercenary1", null); else qry.add("mercenary1", tamer.digimonlist[1].digiid); if (tamer.digimonlist[2] == null) qry.add("mercenary2", null); else qry.add("mercenary2", tamer.digimonlist[2].digiid); if (tamer.digimonlist[3] == null) qry.add("mercenary3", null); else qry.add("mercenary3", tamer.digimonlist[3].digiid);
are sure tamer.digimonlist array of 3 items? cannot see initialized. can make change check first checking array length greater or equal value before check null. instance:
if (tamer.digimonlist.length >= 3 && tamer.digimonlist[3] == null...
this first checks length of array. if less 3, other checks not performed, , should avoid getting index exception.
edit: sorry. need wrapper code because of else. more this:
if (tamer.digimonlist.length >= 3) { if (tamer.digimonlist[3] == null) qry.add("mercenary3", null); else qry.add("mercenary3", tamer.digimonlist[3].digiid); }
Comments
Post a Comment