# Getting the value of an array position.

• 08-03-2010
newn
Getting the value of an array position.
Hi everyone. I will try my best to explain this in english, please ask if i fail:

I have a tile map like that (let's say a small one for somplicity):

Code:

```map[3][3] = { {0, 0, 1}, {1, 0, 0}, {0, 1, 0} }```
I want the guy to be able to walk only on zero tiles. How can i get what is the array value? If it is one or if it is zero? I need to do that check, to let the guy walk on the next time or to stop the guy from moving into that direction.

So question in simple words: how can i check what is the next value of the array, one or zero?

Thanks for help, and please ask, if you don't understand what i need, i will give you a bigger example with more code.
• 08-03-2010
GReaper
Your guy will probably have a x and y placement, right?

Code:

```For Right: if (map[y][x+1] == 0) For Left: if (map[y][x-1] == 0) For Up: if (map[y-1][x] == 0) For Down: if (map[y+1][x] == 0)```
But be careful not to go over the array's limits
• 08-03-2010
shiroaisu
Quote:

Originally Posted by Sipher
Your guy will probably have a x and y placement, right?

Code:

```For Right: if (map[y][x+1] == 0) For Left: if (map[y][x-1] == 0) For Up: if (map[y-1][x] == 0) For Down: if (map[y+1][x] == 0)```
But be careful not to go over the array's limits

for that you could make the x and y of the map a constant and then you could make 2 checks, i to see if the tile is 1 and one to check if the player is leaving the map.

for example:

For Down:
if ((map[y+1][x] == 0) && (y+1 < yconst))

or something like that
• 08-04-2010
newn
Thanks for your answers, helped me a lot. :) Now trying to figure out how to use the for loop properly for this...

Anyway, thanks for help.

P.S. Sipher, i like the quote in your signature, lol.