#### Archived

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

# Levels & disk files

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

## Recommended Posts

If you put your pointers in a structure like that, they'll only be written as pointers. When you re-load the game, what they point to is likely not going to be there anymore. If you already have counters for the number of items in those arrays, you can just leave the pointers as they are and save your tile/enemy data after you save this structure (since you know the number, just write that much data to the file). When you reload, read in your level structure, reallocate the pointers based on the number of tiles/enemies you need, then copy the data back into that memory from the file. If your tile/enemy pointers point to linear arrays, you can just use fread/fwrite to do all the data transfer.

Good luck

Starfall

##### Share on other sites
I am making a level editor and level file format for my game, and I had a few questions about saving the structures to disk. Since one file is going to hold multiple levels, I thought it would make it easier to have a structure sort of like this for one level:
code:
struct Level{char levelNum, tileSet;int length, numEnemies, numPowerups;Tile* tiles;Enemy* enemies;Powerup* powerups;}

Of course, the pointers would be allocated as arrays when the level file is read in, using the length, numEnemies, and numPowerups variables. Would this still save to file correctly if I just wrote a Level object to file, or would I have to cycle through all the members? Also, for the enemies and stuff during the game, would it be better (faster) to use dynamically allocated arrays, or linked lists?

------------------
http://qoy.tripod.com

1. 1
Rutin
47
2. 2
3. 3
4. 4
5. 5

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

• Total Topics
632996
• Total Posts
3009776
• ### Who's Online (See full list)

There are no registered users currently online

×