nml icon indicating copy to clipboard operation
nml copied to clipboard

Provide abstraction for intuitive behavior of "unavailable" variables

Open frosch123 opened this issue 3 years ago • 0 comments

Some VA2 variables are "unavailable" in some contexts, often in the purchase list. When a variable is "unavailable" it does not provide any default value, but rather "throws an exception".

In the "throw" case, the remaining computations in the current VA2 are aborted/not executed, and the "first" case is choosen. (in case of a computed result, the "default" case is choosen).

NML should not expose this surprising behavior as-it to NML users. Instead NML should explicitly "catch" this case:

  • Insert a first case that is unreachable otherwise (e.g. "range 1..0"). (not needed for "computed results")
  • Provide a sane default for the "error" case: "return CB_FAILED" seems reasonable.
  • Bonus: Add an "error: <expression>" similar to "default: <expression>" to switches, for user-defined error-handling.

For details, see: https://github.com/OpenTTD/OpenTTD/blob/master/src/newgrf_spritegroup.cpp#L234 (DeterministicSpriteGroup::Resolve)

frosch123 avatar Mar 30 '21 19:03 frosch123