NMLTutorial/Version check

From TTWiki
< NMLTutorial
Revision as of 21:50, 27 August 2011 by FooBar (talk | contribs) (Add bottom navbar)
Jump to navigationJump to search

Version checks in NML are actually pretty straight forward.

NML provides the global variables openttd_version and ttd_platform. Concerning version checks the built-in function version_openttd comes in very handy as it provides an easy means to specify the version instead of manually constructing the version number corresponding to a specific version.

Thus checking for the TTD platform is simply done by an if block:

if (ttd_platform != PLATFORM_OPENTTD) {
	error(FATAL, REQUIRES_OPENTTD, string(STR_MIN_OPENTTD_VERSION));
	exit;
}

as is the check for a specific OpenTTD (and similarily TTDPatch) version:

/* Only define cargo_age_period when that property is available */
if (openttd_version > version_openttd(1, 2, 0, 22713)) {
	item (FEAT_TRAINS, my_engine) {
		property {
			cargo_age_period: 200;
		}
	}
}

It's also possible to combine these checks into a single block:

/* Long date string codes require OpenTTD > 1.2.0 or r22780 */
if (ttd_platform != PLATFORM_OPENTTD || openttd_version < version_openttd(1, 2, 0, 22780)) {
	error(FATAL, REQUIRES_OPENTTD, string(STR_MIN_OPENTTD_VERSION));
	exit;
}


NML Tutorial: Version check