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

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

Merged
merged 4 commits into from
Jul 10, 2024

Conversation

glx22
Copy link
Contributor

@glx22 glx22 commented Aug 4, 2023

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 glx22 marked this pull request as ready for review August 4, 2023 20:53
@glx22
Copy link
Contributor Author

glx22 commented Oct 5, 2023

Found a perfect use case in 030_house.

regression/030_house.nml Outdated Show resolved Hide resolved
@PeterN
Copy link
Member

PeterN commented Jul 9, 2024

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
Copy link
Contributor Author

glx22 commented Jul 10, 2024

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

@glx22 glx22 merged commit 3739dd4 into OpenTTD:master Jul 10, 2024
21 checks passed
@glx22 glx22 deleted the constant branch July 10, 2024 10:33
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

Successfully merging this pull request may close these issues.

3 participants