# Assigning values to arrays

• 02-25-2003
napkin111
Assigning values to arrays
I'm trying to have a 50x50 array to store a map in, and each number represents a tile. Origionally I had it as a 1D array, and it worked ok...but the AI would have sucked very very bad. Anyway, with my 1D array I did it like this:

int map[5]={25,17,03,10,30);

My question is how do you do this with 2D arrays?

[guess]
int map[5][1]={25,17,03,11,20);
int map[5][2]={23,07,04,10,30);
int map[5][3]={15,13,13,52,30);
int map[5][4]={25,15,03,10,00);
int map[5][5]={22,27,25,13,30);
[/guess]

Thanks!

//napKIN
• 02-25-2003
nextus
well..what if you do this

Code:

`int array[50][50];`
how would assign values to the array now..let me guess...two for loops

Code:

```for(int i = 0; i < 50; i++) for(int j = 0; i < 50; i++) { //whatever here }```
....so it be better initializes it with certain values because assigning different values to each one is sorta hard
• 02-25-2003
napkin111
Ah, thank you Salem. Very much appreciated :D

//napKIN
• 02-25-2003
Noobie
int map[5][5]= {
{25,17,03,11,20},
{23,07,04,10,30},
{15,13,13,52,30},
{25,15,03,10,00},
{22,27,25,13,30},
};

How can u take something like that and create a map out of it?
• 02-25-2003
Perspective
different values represent different map entites...

ex:
27 = draw bush
23 = draw stone
05 = draw water
18 = monster spawn point

you can use pretty much any method you choose.
• 02-26-2003
napkin111
Another question:

Say I do this:
Code:

```int map[5][5]= {   {25,17,03,11,20},   {23,07,04,10,30},   {15,13,13,52,30},   {25,15,03,10,00},   {22,27,25,13,30}, };```
Would map[0][1]==23 or 17? My map is sideways (I make an arrow of trees pointing up, and ingame they face left), and I've looked over my loader a few times, and it seems right to me, but it is loading the maps sideways. I figure it is my error...(actually I've come to assume this in all situations)

Thanks alot!

//napKIN
• 02-26-2003
CheesyMoo
[0][1] would be 17, instead of starting with 1, start with 0, you should end with 4 for each collum and row, so like I have an array
like this:
Code:

```someArry[6] = {0,1,2,3,4,5}; // Each spot has it's adress // value for the array```
Did that make sense?
• 02-26-2003
napkin111
Thanks CeesyMoo (nice name lol), yes that made sense. I asked about map[0][1] because I didn't know how it assigned the values to the array (I thought the "top" might be the left side, that would explain why it is rendering sideways). It must be my maploader, I was correct in assuming I was at fault!

//napKIN
[edited for coherance]