rocket-boots/rote

error when make digger

Opened this issue · 1 comments

x1911 commented

You make a awesome lib, thank you very mush first,

I had tried to make small Dungeon for tutorial, but got this error,
image

image

here is my code,

   _generateMap() {
        /*
roomWidth – [min, max] room size
roomHeight – [min, max] room size
corridorLength – [min, max] corridor length
dugPercentage – algorithm stops after this fraction of map area has been dug out; default = 0.2
timeLimit – algorithm stops after this amount of milliseconds has passed
*/
        var digger = new ROT.Map.Digger(this._w, this._h);  


        var digCallback = function (x, y, value) {
            if (value) { return; } /* do not store walls */

            // var key = x + "," + y;
            // this.mapObj[key] = ".";
            this.mapsArray[y][x] = value  // save in a with all walls, for 
        }
        digger.create(digCallback.bind(this));
    }

how can i avoid it?

This is more of an issue with rot.js rather than this library. I'd recommend checking out the rot documentation, and this bit of code: https://github.com/ondras/rot.js/blob/master/src/map/digger.ts#L111

One thing you might try is using an arrow function as the callback for the create method, similar to what I've done here https://github.com/rocket-boots/rote/blob/master/src/Map.js#L62

digger.create((x, y, value) => {
   if (value) { return; } // do not store walls
   // Not sure how the mapsArray was initialized, but you might need to make sure it has 2 levels of arrays where you need it.
   if (!this.mapsArray) { this.mapsArray = []; }
   if (!this.mapsArray[y]) { this.mapsArray[y] = []; }
   this.mapsArray[y][x] = value;
}