battlecore::config

The config module reads values from the game's config file: the .config.bst script that sits beside the game script and returns one object. Include its declarations with include "./battlecore/config.bst";.

The firmware applies the settings it knows about itself, such as lives, teams and weapons. A game can put any other setting of its own in the same file and read it with this module. The config is the one this tagger read from its own filesystem when the game started.

get

Returns a value from the config by its dotted path. A number in the path picks an array entry. When the key is not there it returns defaultValue, so a game names its defaults where it reads them.

native any battlecore::config.get (string path, any defaultValue = 0);

count

Returns how many entries an array in the config has. It returns 0 when the path is not an array.

native int battlecore::config.count (string path);

Example

A config with settings of the game's own:

return {
	"name": "Capture the Flag",
	"playerLives": 1,
	"flagPickupHoldSecs": 3,
	"flagBearer": {
		"canFire": true
	},
	"flags": [
		{ "id": 1, "team": 0, "name": "Red flag" },
		{ "id": 2, "team": 1, "name": "Blue flag" }
	]
};

The game script reads them by path:

int pickupHoldSecs = battlecore::config.get("flagPickupHoldSecs", 3);
bool bearerCanFire = battlecore::config.get("flagBearer.canFire", true);

int flagCount = battlecore::config.count("flags");
for (int i = 0; i < flagCount; i++) {
	int flagId = battlecore::config.get("flags." + i + ".id", 0);
	int flagTeam = battlecore::config.get("flags." + i + ".team", 4);
}