I'm having a bit of trouble with something....
Basicly I have this array (2 dimensional) that stores tiles (basic div's with colors etc...), one may change the properties of a specific tile by doing;
world[x][y].style blabla somehting
Now, I'm starting to do a bit of pathfinding to be able to walk around on these tiles, lets say I have a 10x10 grid of tiles, ranging from -5,-5 to 5,5 (in coordinates).
I'm sitting on the -5,-5 tile and I click somewhere to "start the pathfinding", my pathfinding thing basicly just finds the 8 adjacent tiles and returns them, then I select the one that brings me closer and I do that X amount of times till I hit my target.
This is no problem if I stand in the middle (0,0) and try to go somewhere, but since I'm in the corner of my "world" I get a few problems when searching for the adjacent tiles;
--# o o o o--
--o o o o o--
--o o o o o--
--o o o o o--
--o o o o o--
Lets say this is my world, # being the character, o being empty tiles and - just being an empty abyss (places where I can't be)
Now I want to go to X;
--# o o o o--
--o o o o o--
--o o X o o--
--o o o o o--
--o o o o o--
So I start my little pathfinding algorithm but when it searches for adjacent tiles from where I am, it returns an error since there is no tiles left, left+down, left+up, or up (from my position.
--# + o o o--
--+ + o o o--
--o o o o o--
--o o o o o--
--o o o o o--
(+) is the tiles that are available but it tries to search for more tiles around me, which results in an error.
I've tried to disclude tiles that doesn't exist by using;
if (world[x][y] !== null) {}
if (world[x][y] != null) {}
if (world[x][y] !== 'undefined') {}
if (world[x][y] != 'undefined') {}
if (!world[x][y]) {}
But then the error is given at the if statement instead of the actuall "tile returning"...
So, how do I precheck if there's something in the array at a specific index (or 2 specific indexe's)?
Also please note that my array does have some gaps, since my world is not only walkable tiles.