I'm new and I need help with arrays

Hello everyone!

I’m new to the world of programming and need help with arrays. I have to do a practice where I have a multidimensional array (attached image) where the first column appears the position X and the second position Y of a String that I have where the name of 18 city appears.

I have to place on an image the name of each city. My doubt is that I do not know how I can do so that with the text function insert a variable that corresponds to the X or Y position of the array.

I would really appreciate any kind of help

Captura de pantalla 2022-06-02 a las 17.58.28

You could save the Strings in an seperate array. And when iterating over the first list can access the corrosponding member in the String array and use that as text.

Hi @JosepAlqueza ,

You can access the array this way.
What about the 3rd column? Is this a id for the cityname !?

void setup() {
   size(1500,1000);
}

void draw() {
    background(0);
    fill(255);
    for(float[] city : cities) {
       float x = city[0];
       float y = city[1];
       float id = city[2]; // what is that number? Id of another array with the citynames ?
       String cityname = "dummy"; // ie citynames[floor(id)] !?
       text(cityname,x,y);
    }
}

If it is 3rd not the id you can extend it by one column and give the entries a number from 0 to rows-1 and make a string array … ie

float[][] cities = {
{232,654,2344555,0},
{554,755,2344555,1}
};

String[] citynames = {
      "cityname1",
      "cityname2"
       // and so on
};

// Then in the above code
// ....
       float id = city[3]; 
       String cityname = citynames[floor(id)];
//....

Cheers
— mnse

1 Like

Hy mnse,

Thanks for your help. It helped me solve my problem.

The third column is the population of every different city

1 Like