Version checks in NML are actually pretty straight forward. If you just want a message without disabling your NewGRF, use one of the other error levels. So if you want to disable your NewGRF with an error message, you use the FATAL error level combined with either a predefined string or a error message of your own. and can be used in custom strings and when defined must be the identifier of a GRF parameter. must be used when one of the predefined messages is used and can either be a string from the language file or a literal quoted string in the NML code. can be one of seven predefined messages (see the NML Documentation) or a custom string (using the string() function). The error function may appear outside blocks, inside if or else blocks, but not inside other blocks.Īdd a notice in the NewGRF status window, continue loading the grf.Īdd a warning in the NewGRF status window, prefixed with "Warning: ", continue loading the grf.Īdd a error message in the NewGRF status window, prefixed with "Error: ", continue loading the grf.Īdd a error message in the NewGRF status window, prefixed with "Error: ", abort loading the grf, also give the error message in a red popup box ingame. The fatal type also disables the NewGRF immediately. The error function allows to issue notices, warnings, errors and fatal error messages.
Again no other code may appear inbetween those blocks (but of course you can have any code you like inside these blocks). You can have as many else if blocks between an if block and an else block as you want. With this, if the first comparison is false, you make a different comparison and when even that is false you get the else. You can also combine an else and if block: An else block must be written directly behind the closing curly bracket of the if block, with no other code inbetween.
The code in the else block is only executed when the condition (for the if block) is not true. The code in the if block will only be executed when the condition is true.
If besides something you want to do when the condition is true, you also want to do something else when the condition is not true, you can add an else block behind the if block: When in doubt, it doesn't hurt to use more brackets than actually needed (as long as they are in the correct places of course!) and they work very similar to brackets in mathematics. In some cases you do not need all brackets, which has something to do with operator precedence we will not bother you with that right now. Things between brackets is evaluated first before combining it with things outside these brackets this makes sure that a certain sub-condition is evaluated to true/false before logically combining it (the comparison operators can compare just about anything, but the logical operators can only combine boolean values). whatever happens when A is bigger than or equal to B and C is not equal to D goes here So for instance if you want to check if A is bigger than or equal to B while at the same time C is not equal to D: Here's a table with the logical operators available in NML: The logical operators can work with boolean values (true or false) to combine multiple comparisons. In case you make multiple comparisons, you can either nest multiple if blocks or combine those comparisons in a single using the so-called logical operators. whatever happens when A is bigger than or equal to B goes here So for example if you want to check if A is bigger than or equal to B: Here's a table with the comparison operators available in NML: The comparison itself is made using a comparison operator which you may already know from different programming languages. The code inside the if block is only executed when the is true. However, you cannot have if blocks inside other blocks (except other if or else blocks and item blocks). The can be anything you would normally write in an NML file, so you can have one or more blocks inside an if block. The usually is a general variable or GRF parameter compared against a static value, a different variable or a different parameter. If the condition is true, the contents inside the switch block is executed, otherwise it's skipped. The if blocks allows to check if a certain condition (for instance based on a general variable or a GRF parameter) is true. The basis of every version check is an if block.