Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Understanding grid[y][x] in gridmancer


I’m having some trouble understanding what this part of the gridmancer example code does

var occupied = grid[y][x].length > 0;
What does the length signify? Why would it be longer than 0 if it’s occupied?

Any available documentation on grid, or advice on how to tell if a coordinate is a wall would be greatly appreciated.


You’re totally right that a little documentation would go a long way. What is actually in grid[y][x] are the Thangs representing the walls that touch this (x, y) coordinate. In this map, there are no overlapping walls, so it’s either one wall Thang (length == 1), meaning occupied, or zero wall Thangs (length == 0), meaning unoccupied.

Hope this helps–eventually you’ll be able to hover over the variable to inspect the data structure and see any further documentation, but we don’t have that yet.


Thank you. That helps a lot.

Hovering over the variable to inspect it’s contents sounds like an extremely useful feature.