Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide abstraction for intuitive behavior of "unavailable" variables #198

Open
frosch123 opened this issue Mar 30, 2021 · 0 comments
Open

Comments

@frosch123
Copy link
Member

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant