TypeError: e.name is undefined after reconnecting to game

Previous topic - Next topic

Dwedit

Got exception on the "return a.name.localeCompare(b.name);" line

        key: "createUniqueInitials",
        value: function createUniqueInitials() {
            var players = this.game.state.players;
            players.sort(function (a, b) {
                return a.name.localeCompare(b.name);
            });
            var previousPrefix = 1;
            for (var i = 0; i < players.length - 1; i++) {
                var prefix = 1;
                for (; prefix < players[i].name.length; prefix++) {
                    if (players[i].name[prefix - 1].toLowerCase() !== players[i + 1].name[prefix - 1].toLowerCase()) break;
                }
                players[i].initials = players[i].name.slice(0, Math.max(previousPrefix, prefix));
                previousPrefix = prefix;
            }
            if (players.length > 1 && players[players.length - 2].name.length === previousPrefix) previousPrefix += 1;
            players[players.length - 1].initials = players[players.length - 1].name.slice(0, previousPrefix);
            players.sort(function (a, b) {
                return a.index - b.index;
            });
        }

Ingix

Thanks for the report. Some info seems to have been lost after the reconnect.

Dwedit

Seeing this happen again:

        value: function createUniqueInitials() {
            var players = this.game.state.players;
            players.sort(function (a, b) {
                return a.name.localeCompare(b.name);
            });
            var previousPrefix = 1;
            for (var i = 0; i < players.length - 1; i++) {
                var prefix = 1;
                for (; prefix < players[i].name.length; prefix++) {
                    if (players[i].name[prefix - 1].toLowerCase() !== players[i + 1].name[prefix - 1].toLowerCase()) break;
                }
                players[i].initials = players[i].name.slice(0, Math.max(previousPrefix, prefix));
                previousPrefix = prefix;
            }


Upon entering this function, the array `this.game.state.players` contains two elements.

this.game.state.players[0].name = undefined
this.game.state.players[1].name = "Dwedit"

Then it crashes when it attempts to sort the players, and the game never starts.

---

It is actually possible to manually get past this one:

* Set a JavaScript breakpoint at the `var players = this.game.state.players;` line
* Go to Console, and assign `this.game.state.players[0].name = "OPPONENT"` (if players[0] was the one without a name)
* Resume execution

When I finally got past it, I saw a "make opponent resign" prompt.  The opponent was probably was having issues too.