Jump to content
  • Advertisement
Sign in to follow this  
bschneid

how to access my array-ed data members

This topic is 4427 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!