User Tools

Site Tools


tutorials:changing_default_config_file

Changing the default application configuration file

When an Orx game or application starts, the matching config data file is expected to reside in the same folder as the executable, and to have the same name as the executable, minus the extension. For example:

bin/AlienAttack.exe
bin/AlienAttack.ini

When first executing the AlienAttack.exe file, the default bootstrapping seeks for the AlienAttack.ini file and begins processing it before Orx processes the init() function.

This default behaviour can be changed, allowing you to load your root configuration file from a completely different location, and with a completely different name.

This is done by adding a Bootstrapping function like so:

orxSTATUS orxFASTCALL Bootstrap() 
{ 
 
	// Add "../../data/config" to the list of locations that config files can be loaded from
	orxResource_AddStorage(orxCONFIG_KZ_RESOURCE_GROUP, "../../data/config", orxFALSE); 
 
	// Loads a specific config file 
	orxConfig_Load("MyRootConfig.ini"); 
 
	return orxSTATUS_FAILURE; 
}

orxConfig_Load is used to call the new root config file of MyRootConfig.ini. Because we added the new config resource path previously, Orx knows where to try and find the config file.

The return status is set to orxSTATUS_FAILURE. This effectively stops Orx from continuing to look for a default config, after the Bootstrap function has completed. If orxSTATUS_SUCCESS is returned, Orx will still try and load the default config located next to the executable, eg: AlienAttack.ini

Next, in the main() function, set the Bootstrapping function before the orxExecute line:

int main(int argc, char **argv) 
{ 
  orxConfig_SetBootstrap(Bootstrap); 
 
  orx_Execute(argc, argv, Init, Run, Exit); 
 
  return EXIT_SUCCESS; 
}   

Your application will now call its root .ini file from some other location relative to the .exe.

tutorials/changing_default_config_file.txt · Last modified: 2017/05/30 05:50 (8 weeks ago) (external edit)