Error in my code [Please don’t swear]


#1

Hello,

My code is

var grid = this.getNavGrid().grid;
var tileSize = 8;
for(var y = 0; y + tileSize < grid.length; y += tileSize) {
    for(var x = 0; x + tileSize < grid[0].length; x += tileSize) {
        var occupied = grid[y][x].length > 0;
        var occupied_deux = grid[y][x + 5].length > 0; //ERROR WITH + 5 
        var occupied_trois = grid[y + 5][x].length > 0; //ERROR WITH + 5
        if(!occupied && !occupied_deux && !occupied_trois) 
        {
            this.addRect(x + tileSize / 2, y + tileSize / 2, tileSize, tileSize);
            this.wait();  // Hover over the timeline to help debug!
        }
        else if (!occupied)
        { 
        this.addRect(x + tileSize / 2, y + tileSize / 2, 4, 4);
        }

The error is : Line 2902: TypeError: tmp57 is undefined
This code worked but now it doesn’t work…
How i’m supposed do an operation ?

Thanck for your futur help. (If my english is not good that’s because i’m not english)


#2

Hi programmezero,

Can you let me know if you see the same error message in Google Chrome? I’m tracking a bug with this right now where the error message is obfuscated like this in Firefox and Safari: https://github.com/codecombat/aether/issues/5 – I wonder if that’s what’s going on here.

The error message should be pointing out that something like grid[y][x + 5].length or grid[y + 5][x + 5].length is trying to access a property of undefined, perhaps because grid[y][x + 5] is outside the end of the grid and thus undefined and doesn’t have a length property.

Sorry about this! Will be working on getting the error messages much improved, and with line numbers. Before then it’s pretty frustrating to debug things like this.