how to access my array-ed data members

Started by
2 comments, last by Replicon 17 years, 10 months ago
This problem came up when I was working on a new 2d tiled game. I have a class called Tile. Tile has a variable called "type" which defines the sort of tile to be drawn (grass, dirt, etc). I then have a class called Map which stores an array of Tiles. The problem arises when I try to define the map by giving different tiles different values so that there are different types of terrain. I need to know how to set the "type" values for Tile. I know I can access them like Map.ArrayOfTiles[x][y].Type = whatever, but is it possible to define them all at once like you would an array (like this: {1,2,3,4})? I know that's not very clear, but I hope you understand. I can try to explain more if needed.
Advertisement
I don't believe so, or at least it won't be very easy with big maps. It would be best to either load the information from a file, or to generate it with a loop or two.

You can only go like so array[5]={1,2,3,4,5} when array[] is declared, and since you cannot assign member data a value in the same line it is created, I don't believe that you can do this.
Ok, thanks for the quick reply.
I would go through the effort of loading it from a file with arbitrary dimensions. Do you really want to be hand-coding some CPP constant and rebuilding constantly?

This topic is closed to new replies.

Advertisement