OpenTTD / OpenTTD/nml

Provide abstraction for intuitive behavior of "unavailable" variables

Open
#198 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
58
Forks
46
Avg merge
11d 15h
Merged PRs (30d)
3

Description

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)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced Resolve implementation in src/newgrf_spritegroup.cpp around line 234 to understand how unavailable variables affect switch and computed-result evaluation. Then locate the corresponding NML variable and switch handling; done means unavailable cases are caught, first/default behavior is explicit, and the proposed error expression is considered or implemented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.