Saturday, August 15, 2009

The house was decorated by an evil dolphin

I now have weapon deletion working (but not with the fancy JQueryUI blind effect I want), but I had to do something weird with my weapons array. Simple remove of the weapon from the array:

chardata.weapons.splice(weapon_idx, 1);

does not "reorder" the array. Eg.,

[{foo}, {bar}, {monkey}].(splice(1))


does not just create [{foo}, {monkey}]. It's stored as

["0":{foo}, "2":{monkey}]

which causes a problem with the way I'm handling the UI. My solution was to copy the array with slice(), then reassign it back to the real chardata object:

chardata.weapons.splice(weapon_idx, 1);
var foo = chardata.weapons.slice();
chardata.weapons = foo;

The indexes are sequential with no gaps. Weird, but it works.

No comments: