   Loading Data From Files (C++)
  So far, I have been hard-coding all of the objects in my game.  I need to make a system to load objects through data files (preferably text formatted so they can be edited in notepad).  I would probably have a main file that contains a list of all the other object files to be loaded.  Then have all of the actual object files contained in the same folder.I don't really know how I could create new objects based off of what a text file says though.  I was thinking I should be using fstream, but is that what I should be using?   
  What do you mean by "objects"?  The actual definition of things in your game, or a level containing instances of said objects, and a tile-map made up of numbers reffering to textures.  And maybe a list of tile gfx files, or one gfx file.What I'm asking is what is what values are you coding into your game that you feel should be in a file?Also, to load files from a disc it would be ok to use fstream to read a binary or text file.   ;  I wan't to have the stuff like movement speed, health, and the such all stored in a text file for that object.   Then in a level file, represent that object as a number for a specific location.   ;Quote:Original post by bluehailexObjects meaning characters, trees, buildings.think about the data that makes these things up. A tree for example could be a position and size. I prefer using text files using xml. so I would just right it out to a text file like so.<tree>  <position x="230" y="230" />  <size s="4" /></tree>Your level loader should be able to parse that and know that there is a tree with a size of 4 at position 230x230.   ;  It's really up to you. You could come up with some custom data definition format, and then parse data files manually by reading them in through an fstream. You could also look into an established data format, like XML, and try to find a library to parse it for you. In my current project, I use Lua as a data definition language and Luabind to interface with it. Any of the above might be desirable, depending on your circumstances.   ;  What should I do to actually declare a new object.  In my game, I am using a struct for the object.  So basically, I want to load the info from the file and create a new object of that structure.  So does that mean I need a parser for that?   ;  There's no one correct way to do this.  That being said...If you are defining the objects within the game--for example saying that object "goblin" has a health of "4", an attack strength of "2", and so on--then in your level file you could have the typical list of numbers for tile types, then after that have a list of  objects that populate your world.  Example://HEADER5 // map width5 // map height3 // object count0 0 0 0 00 0 1 1 00 0 1 0 00 0 0 2 00 1 1 0 2GOBLIN 1, 1CHEST_CONTAINING_HEALTH 1, 3PLAYER_ENTRANCE 4, 0;  What you are really looking for is "Serialization" or "Scripting".Boost::Serialization is a fairly straight forward implementation of the the first technique.You'd take your objects, with their "health" "speed" and other attributes, and write 2 (or 1 if you use that interface) functions, one to write to a boost archive, and one to read from it.A more simplistic take you can do for learning purposes, is write out a simple file format likename Bobhealth 15speed 2Using fstream, you'd read in one string, see what it is "name" "health" "speed", and using a big if-else block, choose based on that token what to read in next, and where to store it.In either case, some tokens in your text file would indicate "you need a new object". So you'd create a new object, then de-serialize the data from the file into that object.The other option is "Scripting". You could use something like tolua++ to translate your C++ code into lua bindings. You'd then write plain text lua scripts that contain all the instructions to create a level.  These instructions get parsed by the lua interpreter where they'd call the appropriate C++ functions to create your objects and set their values.-edit... wow, i'm way slow on the posting today.   ;  Ok.  So once I am able to get the attributes from the file, how do I create the actual object of the structure.  Such as: struct CHARACTER{  int health;  int attack;};CHARACTER goblin;Like how to I declare goblin without knowing goblin will be declared before I compile the game?   ;  by using dynamic allocation of one form or anotherstd::vector< CHARACTER > characters;void loadLevel(){ std::fstream file("level.txt"); std::string token; file >> token;  if( token == "goblin" ) {characters.push_back( CHARACTER() );LoadGoblin( file, characters.back() ); }}void LoadGoblin( std::fstream &file, CHARACTER &c ){   file >> c.health >> c.attack;}with a file that looks like:goblin 15 5