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

Fix: Access to persistent storage of towns #173

Merged
merged 4 commits into from May 23, 2021

Conversation

frosch123
Copy link
Member

@frosch123 frosch123 commented Dec 3, 2020

This PR adds a distinction between 'features' and 'scopes' (defined by feature+self/parent), instead of identifying both with interchangeable integers.
This fixes access to persistent storage to towns. (see #26, #28, https://www.tt-forums.net/viewtopic.php?p=1220012#p1220012 )

@andythenorth
Copy link
Contributor

\o/

@frosch123 frosch123 marked this pull request as ready for review February 22, 2021 20:24
Identify variable-scopes using a dedicated class instead of feature numbers.
The later fails for towns, which have no feature number.
@Andrew350
Copy link

I'm not sure what it's worth, but I just tested this PR with my NewGRF, and I'm now able to successfully store a value via an industry and then read that value from a house to conditionally allow/disallow construction. So it seems to work for me 🙂

Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine, can't speak for its correctness

self.parent_scope = parent_scope

def get_scope(self, var_range):
assert var_range in (0x89, 0x8A)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asserts get removed in optimised builds (like Windows exe), and I think most others have been replaced with an explicit raise AssertionError. Not necessarily an issue, but something to consider?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We removed all "assert False". If they were removed in release builds, they would open up new code paths.
A tool warned about that.
Regular asserts are fine.

var_feature = action2var.get_feature(self) # Feature of the accessed variables
var_scope = action2var.get_scope(feature, self.var_range)
if var_scope is None:
raise generic.ScriptError("Requested scope not available for this feature.", self.pos)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate issue to deal with, but most ScriptErrors do not have a trailing '.':

$ grep -R "raise generic.ScriptError" nml | grep '[.]"[^"]*$' | wc -l
131
$ grep -R "raise generic.ScriptError" nml | grep '[^.]"[^"]*$' | wc -l
284

Copy link
Member Author

@frosch123 frosch123 Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most messages in this file have a trailing colon.
Some of those which do not end with ".", end with ":" followed by some source quotation.

Copy link
Contributor

@glx22 glx22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems correct, and it's a lot more cleaner than the old way.

@frosch123 frosch123 merged commit 4444c13 into OpenTTD:master May 23, 2021
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.

None yet

5 participants