Sign in to follow this  
Mizipzor

cfg files?

Recommended Posts

Mizipzor    247
Up until now I got my maps data stored in txt's. I know in which order the variable comes so I just do: name = file.getline(); movementcost = file.getline(); And the txt file would look like: grassland 5 But I want to remake it so I in the file just wrote: name = grassland movementcost = 5 And the program stores the values itself. Many games Ive played uses this system for configuration stuff, I searched google for cfg tutorials but couldnt find any. Anyone knows of any good? Or is it so short and easy so that you can tell me here? Thanks in advance, and sorry if you can find it on google, I guess I suck at google searches then... :P

Share this post


Link to post
Share on other sites
Illco    928
It is really simple (especially when compared to other game development techniques). I don't know which language you are using so I'm keeping this abstract. What you do is read one line of the file into a buffer. Then 'tokenize' this buffer, or split it on the equals-sign, anyway, such that you have a left part and a right part. The left part should be checked to see which property is set. The right part should give the value.

Greetz,

Illco

Share this post


Link to post
Share on other sites
ext    180
cfg files are just small ini files, I'm using always ini files and it gives you a greater control due to ordering them in logic blocks.

Share this post


Link to post
Share on other sites
Motz    136
This may not apply now, but it's useful for larger projects. If you're going to be embedding a scripting language in your game/application, then cut out the middle man (i.e. Writing and parsing your own configuration format) and make your config file a script which sets the required variables, calls the required functions, etc. That way, all it takes a simple call to your scripting engine's "execute" function, rather than the extra effort of an entire extra configuration reading/writing module.

However, if you aren't planning on using scripting, XML could be a good choice, provided that you're dealing with a large amount of complex data. The overhead isn't worth it for 5 lines of "key = value" pairs, but for larger sets of data, it is worthwhile, since there exist several highly optimized libraries dedicated to reading and writing it. The ability to modify a document in place makes it possible to write a configuration tool, rather than requiring the user to open the file up in Notepad or whatever (although they could if they so desired, since XML is human readable).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this