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 bounds checking for getTerrainAt #94

Merged
merged 1 commit into from Aug 28, 2018

Conversation

Projects
None yet
2 participants
@magnostherobot
Contributor

magnostherobot commented Jul 7, 2018

Currently, if the user passes an x,y-pair into Game.map.getTerrainAt, that are out of bounds, the returned value is confusing:

  • If x is too large, it will wrap around to next y values.
  • If x is negative, it will wrap around to previous y values.
  • If y is too large or negative, it will return 'plain'.

Having the return value instead be undefined in these cases makes it clearer to users debugging malfunctioning code what is going on. Additionally, it returns false when compared with 'plain', making searching for free spaces near mining spots a lot easier for new players.
If being able to disable bounds-checking is desired, it would be easy enough to include this functionality as an optional boolean argument for the function.
The docs (specifically https://docs.screeps.com/api/#Game.map.getTerrainAt) will need to be edited to include this change.

Add bounds checking for getTerrainAt
Currently, if the user passes an `x,y`-pair into `Game.map.getTerrainAt`,
that are out of bounds, the returned value is confusing:

- If `x` is too large, it will wrap around to next `y` values.
- If `x` is negative, it will wrap around to previous `y` values.
- If `y` is too large or negative, it will return `'plain'`.

Having the return value instead be `undefined` in these cases makes it
clearer to users debugging malfunctioning code what is going on.
Additionally, it returns `false` when compared with `'plain'`, making
searching for free spaces near mining spots a lot easier for new players.

@artch artch added the ptr-staging label Aug 28, 2018

@artch artch changed the base branch from master to ptr Aug 28, 2018

@artch artch merged commit 3536a9a into screeps:ptr Aug 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment