# Help on searching my Map Array

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

## Recommended Posts

I have designed my maps so that they are in 2d arrays. I have defined one of my tiles attribs to have a start_level which equals 1. eg (tile.start_level =1). I am having a problem, about how do I go about scanning my map to find this tile and then placing my character on that tile. I'm going about it like this: for (int x = 0; x<=255; x++) { for (int y = 0; y<=255; y++) { //IF current position on the map is equal to start_level ==1// if(tiles[Map_Array[x][y][0].start_level==2) //) is the layer //DRAW THE CHARACTER AT THIS TILE// } } Any help on what I'm doing wrong would be greatly appreciated! Thanks

##### Share on other sites
If it is just one tile, it might be easier just to create a structure holding the (x,y) coordinates of that tile and using it to locate your character. It would save on both the search time as well as the memory used for describing each tile.

Another idea would be to have a single subscripted array made up of the (x,y) coordinates of the start tile for each level.

##### Share on other sites
I'd say that special cases like this call for holding a pointer to the tile in question, not for setting a variable. Since you're only going to have one tile where start_level == 1 anyway, you're basically special-coding the start tile location into memory (except that you're spending a few extra bytes for every other tile to say that it's not the start location). So if you're going to special-code this, you might as well make it easy on yourself. When you first find out which tile is the start location (i.e. when you would normally do start_level = 1), just set a pointer to the start location, that you can access when you need to find out where the start location is.

##### Share on other sites
Once you find the right tile to start on (looks to me like you figured that out already :)), just set the player's position to the position of the tile.

##### Share on other sites
I figured out the problem, found an error in my code to position my character at that location

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632995
• Total Posts
3009774
• ### Who's Online (See full list)

There are no registered users currently online

×