Thread: Assigning values to arrays

  1. #1
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310

    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
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  2. #2
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    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

  3. #3
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Ah, thank you Salem. Very much appreciated

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  4. #4
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    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?
    AIM: MarderIII

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    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.

  6. #6
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    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
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  7. #7
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    [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?

  8. #8
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    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]
    Last edited by napkin111; 02-26-2003 at 08:56 PM.
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Arrays!
    By J-Camz in forum C Programming
    Replies: 3
    Last Post: 11-27-2008, 02:35 AM
  2. trouble assigning arrays
    By shintaro in forum C++ Programming
    Replies: 8
    Last Post: 11-21-2008, 08:31 AM
  3. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  4. Assigning values to arrays using fscanf
    By Hallu in forum C Programming
    Replies: 5
    Last Post: 03-24-2004, 05:50 PM
  5. Confusion with assigning values to structs.
    By Tronic in forum C++ Programming
    Replies: 9
    Last Post: 03-22-2004, 08:01 AM