Sep 1, 2014 at 6:21pm UTC
I have an object:
Ctile tile;
And i have a loop:
1 2 3 4 5
for (int r = 0;r < 50;r++) {
}
What i want is:
Inside the loop, create a new Tile for each r(row).
1 2 3 4 5
for (int r = 0;r < 50;r++) {
// =>> inside here <====
}
Because CTitle have 2 int
X and Y.
So Y will be = r.
and X = l, for the other loop.
Last edited on Sep 1, 2014 at 8:44pm UTC
Sep 1, 2014 at 8:55pm UTC
There are numerous ways to do this. The easiest would be to have a container store them all such as a std::vector
. You could also use dynamic arrays if you really wanted to.
Sep 1, 2014 at 8:57pm UTC
i know how to use a vector like TileList and push the Tile.
But i don't know how to create a new Tile inside the loop for each new r.
Last edited on Sep 1, 2014 at 8:57pm UTC
Sep 1, 2014 at 9:11pm UTC
Shouldn't you create a new tile for each column? Something like:
1 2 3 4 5 6 7 8 9 10
std::vector<std::vector<Tile> > map;
for (int row = 0; row < rows; ++row)
{
std::vector<Tile> tempRow;
for (int column = 0; column < columns; ++column)
{
tempRow.emplace_back(column, row, TILEID); //x, y, type of tile
}
map.push_back(tempRow);
}
Last edited on Sep 2, 2014 at 7:13pm UTC
Sep 2, 2014 at 11:17am UTC
CMapGen.cpp:28:24: error: redeclaration of ‘std::vector<CTile> row’
std::vector<CTile> row;
^
CMapGen.cpp:26:9: error: ‘int row’ previously declared here
for(int row = 0; row < rows; ++row)
^
Sep 2, 2014 at 7:13pm UTC
Well, the error is pretty straight forward. I didn't realize when I typed it up earlier but I wasn't telling you what to use it was an example of how you could do it.
Sep 2, 2014 at 7:46pm UTC
I'll test here.
Last edited on Sep 2, 2014 at 7:52pm UTC