LuaSurface.set_tiles parameter to offset tile positions
Posted: Sat Sep 14, 2024 5:39 pm
I have a block of tiles that I want to place copies of multiple places in the world. I'd like to initialize the definition of those tiles just once, then call set_tiles with a MapPosition that will get added to the positions of all of the tiles in my block.
Currently I am doing this which saves time creating the table but still requires me to loop through to set all the positions:
I'd love to be able to just do this:
Currently I am doing this which saves time creating the table but still requires me to loop through to set all the positions:
Code: Select all
local blank_tiles = {}
for count = 0, 32*32-1 do
-- position will be updated before placement
blank_tiles[count] = {name= "out-of-map", position= {0, 0}}
end
local function wipe_chunk(surface, pos)
for dx = 0,31 do
for dy = 0,31 do
local blank_tile = blank_tiles[dy*32+dx]
blank_tile.position.x, blank_tile.position.y = pos.x + dx, pos.y + dy
end
end
local tile_correction = false -- causes problems with deep water
surface.set_tiles(tiles, tile_correction)
-- ...
Code: Select all
surface.set_tiles(tiles, tile_correction, pos)