• ### Popular Now

• 11
• 27
• 9
• 20
• 31

#### Archived

This topic is now archived and is closed to further replies.

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

## Recommended Posts

Hi. Until now, I haven''t really been using any other maps except the one "test map" in my tile-based game, and I''ve hit a problem. By the way, I am not loading the maps from an external file, they are all declared in the source. I have the 2d map array variable called map[40][40] and I define it in a initialization function. Dandy. In my game, there''s a "pick-a-level-screen" similar to that of DxBall 2, and once a level is picked from the screen, there''s a call to the map loading function which goes something like this.  //... if (level == 1) char map[40][40] = ... //declare the map. else if (level == 2) char map[40][40] = ... //declare the map for the 2nd level. //...  From there, the main game loop should be entered and the map that was loaded into map[40][40] should be used for the gameply. PROBLEM: I don''t know what the problem is (of course!), but no tiles are being drawn, as if the map was never declared. And, yes, I''m sure that in the level picking screen, the int variable level is assigned to the map that was picked. And, yes, I use the same method for defining a map in an initialization function, for example, as I did in the map loading function. And, yes, I know that this routine (even if it did work) would not be good at all, but I just want to get this done. I feel really stupid for asking this question, as the answer is probably a stupid thing that I did for the assigning of the new maps. Thank you very much, Martin

##### Share on other sites
try using the 'new' keyword. this creates a "new" array.
  new char map[40][40]=...

or something like that

JoeMont001@aol.com www.polarisoft.n3.net

Edited by - Julio on July 12, 2000 9:01:21 PM

##### Share on other sites
Julio: Thanks for the suggestion, but it didn''t work for some reason. I think my problem is that 2dimensional arrays (if not all arrays) are constant. I''ll keep working on it.

Any more suggestions?

Thanks,
Martin

##### Share on other sites
Hey lpsoftware.

Well, Im not sure what could be wrong... Could ya post a bit of your code?

Like one whole 40x40 declaration of the map, or something. Maybe the prototype of this function you posted a bit, the variable declaration, the first "if (level == 1)", the last and the function closing.

Just a bit more of code so we can analyze it and see if something is wrong .
Ah and use (source) + (/source), its much more readable than (code) + (/code). Change the ()''s to the proper chars that you know.

Cya,
-RoTTer

##### Share on other sites
yeah, post the function where you initialize your map or the first time, then post the function where you "declare" the map. I think your problem is either one of scope or one of conflicting data types(not sure though)

"Innocent is just a nice way to say ignorant, and stupidity is ignorance with its clothes off."

words of,
skitzo_smurf

##### Share on other sites
  //...if (level == 1)char map[40][40] = ... //declare the map.else if (level == 2)char map[40][40] = ... //declare the map for the 2nd level.//...

If this is what your function looks like (it''s the code you posted in the original message), then your map variable
(char map[40][40]) only exists inside the if statement, I believe.

Therefore, you should declare it externally and then initialize it according to the level selected.

If this is not the case, you''ll have to post your code.

##### Share on other sites
Hey

Nice point, anon poster .

Im not sure also if thats the problem but is very likely it is, or the compiler wouldnt allow multiple "char map[40][40]" if the var isnt killed after the if (the compiler doesnt know it will fail in the other ifs... or does it (cause of the else''s)? oh well).
Anyway, it seems anon poster got whats the problem already. Confirmation, lp?

Cya,
-RoTTer

##### Share on other sites
Anon Poster, thanks for the suggestion, but I tried doing just

map[40][40] = //...

before I posted the question. It still doesn''t work that way. However, I figured out a new way to do it:

for (int x = 0; x < SCR_WIDTH; x++) {
for (int y = 0; y < SCR_HEIGHT; y++) {

level1map[x][y] = map[x][y];
}
}

...where level1map is the map defined in an initilization function for "level 1" and map is the map used throughout the gameplay and for all of my functions. I''m supposing that since I''ve been changing individual members of my 2d map array throughout the whole development process, I can do it here. For some reason, I can''t change the thing as a whole, but I can change the individual members. BTW, this isn''t tested yet so I''m not sure if it''s 99% correct, or 1% for that matter.

Anyway, more suggestios are welcome and thanks for the help.

Martin

##### Share on other sites
shouldn''t it be

map[x][y] = level1map[x][y];

??

##### Share on other sites
Why don''t you just work with dynamic array''s.

  int Width, Height;int **Map;//read map width and height and put them in the vars//create map arrayMap = new int*[Height];for(int i=0; i = new int[i][Width];

I think this should work, though I''m not sure since I haven''t been able to test it.

The Rock