nml icon indicating copy to clipboard operation
nml copied to clipboard

Change: Unreachable range for default only switch should target CB_FAILED

Open JGRennison opened this issue 1 year ago • 0 comments

The unreachable range for default only switches should target the CB_FAILED group, instead of returning a success value of 0.

This is because the current success value of 0 interacts unfavourably with other unfortunate quirks of the GRF spec and how callbacks are handled.

  • The error group for a deterministic sprite group is the first range group (not the default group), so it is the unreachable group in this case.
  • For historical reasons, unhandled callbacks are routed onto the graphics chain. (This anti-pattern should be removed, but this is outside the scope of this PR).
  • Many key callbacks are unmasked and so always executed, therefore will end up on the graphics chain if not explicitly handled in the NML source. In particular this includes callback 36.
  • Variables such as vehicle variable 61 are fine when called in a graphics context but route to the error group for most callbacks.

The result of this is that a switch which can trigger a variable error in the graphics chain can result in unrelated callbacks inexplicably succeeding with a value of 0. In the case of callback 36 this can lead to all sorts of weird behaviour. This PR changes this behaviour to the callbacks returning a failure result as expected.

JGRennison avatar Apr 29 '24 17:04 JGRennison