Difference between revisions of "NMLTutorial/Version check"
From TTWiki
Jump to navigationJump to searchPlanetmaker (talk | contribs) (how to do version checks) |
Planetmaker (talk | contribs) m (use common style for <code>) |
||
Line 1: | Line 1: | ||
Version checks in NML are actually pretty straight forward. |
Version checks in NML are actually pretty straight forward. |
||
− | NML provides the [http://newgrf-specs.tt-wiki.net/wiki/NML:General#General_variables global variables] <code |
+ | NML provides the [http://newgrf-specs.tt-wiki.net/wiki/NML:General#General_variables global variables] <code>openttd_version</code> and <code>ttd_platform</code>. Concerning version checks the built-in [http://newgrf-specs.tt-wiki.net/wiki/NML:Builtin_functions function] <code>version_openttd</code> 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: |
Thus checking for the TTD platform is simply done by an if block: |
Revision as of 09:01, 26 August 2011
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; }