Using Game Data Configuration Files

You can specify named assets of type Integer, Single, String, and Boolean which will be loaded at game start and will then be available through the AssetManager. The AssetManager contains a GameDataFile property which can be set to the name of a text file (with extension cfg) added to the Assets folder. The AssetManager will look for GameDataFile.cfg in the Assets folder and if it is found it will load the values contained within.

Writing a Configuration File

The configuration file is a plain text file which can be written in any text editor, such as Notepad or Visual Studio Text file. The file will contain lines which begin with an identifing token character and are seperated by a new line character (return). The first character of each non-blank line must be one of the following token characters (any blank lines will be ignored):

Line Tokens

  • ! = Comment
  • @ = String Value
  • # = Integer Value
  • $ = Single (Float) Value
  • % = Boolean (Flag) Value
The token character can then be followed by optional white space (such as a single space), and then must be followed by the name/value pair for the asset, seperated by an equals sign (=). Any amount of white space may exist between the equals and the name/value.

Names should be composed using the same rules as for file names.
All assets of a given type must have unique names. It is best practice for all assets to have unique names regardless of type.

Values must be parsable into their cooresponding types. So an integer asset must have a whole-number value, a Single asset can optionally have a decimal point, and a Boolean value should be entered as "True" or "False".

Here is an example of a configuration file using blank lines and comments for organization:

Example File

! A Sample Game Data File

! Some global strings:
@ Player Name = Stars
@ Title = Test Game

! Some sample flags:
% IsConditionGood = True
% DidWarpActivate = False

! Some sample numbers:
# Score = 0
$ Distance = 7.325

Last edited Jan 2, 2012 at 9:05 PM by ReedKimble, version 2


No comments yet.