OpenTTD / nml

NewGRF Meta Language
GNU General Public License v2.0
42 stars 36 forks source link

Add: 'const' keyword to allow users to define new constants #302

Closed glx22 closed 2 months ago

glx22 commented 1 year ago

It's possible to use named parameters as constants, but it doesn't always work and it's not very efficient in the resulting GRF when it does work.

Introduce the const keyword and const <name> = <value>; syntax, which will define the constant <name> to the value <value>.

Constants should be usable like any of the predefined constants so I delayed some validations for item and disable_item as they were happening too early.

glx22 commented 11 months ago

Found a perfect use case in 030_house.

PeterN commented 2 months ago

Have I understand this correctly? When not marked as const, the named parameter may be allocated a GRF parameter which is then dereferenced when used instead of simply storing the value where used.

glx22 commented 2 months ago

Exactly, named parameters are just GRF parameters, with all the implied limitations in usage.