Page 1 of 1

[1.1.69] not-modded luasurface.get_tile() returns invalid tile

Posted: Tue Sep 20, 2022 12:13 am
by Honktown
If a tile is in a chunk that's not generated(?) get_tile returns an invalid tile:
1) start new game

Code: Select all

/c
local tile = game.player.surface.get_tile(1000, 0)
game.print(tile.name)
Expectation: The game should not return invalid objects. No tile (new change) or valid tile should be the only returns?

Re: [1.1.69] not-modded luasurface.get_tile() returns invalid tile

Posted: Tue Sep 20, 2022 12:23 am
by Rseding91
Thanks for the report however I don't see this changing in 1.1 since it would break every mod that uses the API and expects non-nil from the function call. It has worked that way since it was added and can easily be .valid checked to see if the chunk exists.

We could probably change it for 1.2.

Re: [1.1.69] not-modded luasurface.get_tile() returns invalid tile

Posted: Tue Sep 20, 2022 2:33 pm
by curiosity
You probably should. It's a pretty major expectation.

Re: [1.1.69] not-modded luasurface.get_tile() returns invalid tile

Posted: Tue Sep 20, 2022 2:43 pm
by Rseding91
curiosity wrote: Tue Sep 20, 2022 2:33 pm You probably should. It's a pretty major expectation.
You didn't say what should be done.

Re: [1.1.69] not-modded luasurface.get_tile() returns invalid tile

Posted: Tue Sep 20, 2022 2:45 pm
by curiosity
Rseding91 wrote: Tue Sep 20, 2022 2:43 pm You didn't say what should be done.
Maintain the expectation.

Re: [1.1.69] not-modded luasurface.get_tile() returns invalid tile

Posted: Tue Sep 20, 2022 10:52 pm
by Xorimuth
Surely any mod that is expecting a non-nil result from get_tile is also expecting a valid result? What could a mod do with an invalid LuaTile that it can't do with a nil LuaTile?

Re: [1.1.69] not-modded luasurface.get_tile() returns invalid tile

Posted: Wed Sep 21, 2022 4:51 pm
by pleegwat
The existing interface is that a LuaTile is always returned and you need to check .valid. So most likely all existing mods assume the returned value is non-nil and check .valid, which would trigger an error if they suddenly got nil.

Re: [1.1.69] not-modded luasurface.get_tile() returns invalid tile

Posted: Wed Sep 21, 2022 10:25 pm
by curiosity
pleegwat wrote: Wed Sep 21, 2022 4:51 pm The existing interface is that a LuaTile is always returned and you need to check .valid. So most likely all existing mods assume the returned value is non-nil and check .valid, which would trigger an error if they suddenly got nil.
Supposedly they check valid. Most likely, I would guess, they don't.