Page 1 of 1

Problem with set_tiles(tiles, correct_tiles)

Posted: Fri Mar 17, 2017 12:24 pm
by Maniah
I'm creating a "border" in water around a plot of land. I use the set_tiles function for this. When I set correct_tiles to false: everything works great:
Image

But when I set it to true, I get a different result every time. An example:
Image

When I click the button enough to generate the border, it eventually get there. But that's not a workable solution.

Full code:

Code: Select all

function plot_moat_change(event, plot_number, tile_type)
	local player = game.players[event.element.player_index]
	local surface = player.surface
    
	local waterTiles = {}
	local x = 0
	local y = 0
	local distance = PLOT_SIZE - (PLOT_INNER_CORNER_OFFSET * 2)
		
	-- Top left to Top Right
	--distance = global.plot_table[plot_number]["inner_corners"]["top_right"][1] - global.plot_table[plot_number]["inner_corners"]["top_left"][1]
	x = global.plot_table[plot_number]["inner_corners"]["top_left"][1]
	y = global.plot_table[plot_number]["inner_corners"]["top_left"][2]
	
    for i=0,distance,1 do
        table.insert(waterTiles, {name = tile_type, position={x+i,y}})
    end
	
	-- Bottom left to Bottom Right
	x = global.plot_table[plot_number]["inner_corners"]["bottom_left"][1]
	y = global.plot_table[plot_number]["inner_corners"]["bottom_left"][2]
	
    for i=0,distance,1 do
        table.insert(waterTiles, {name = tile_type, position={x+i,y}})
    end

	-- Top left to Bottom left
	x = global.plot_table[plot_number]["inner_corners"]["top_left"][1]
	y = global.plot_table[plot_number]["inner_corners"]["top_left"][2]
	
    for i=0,distance,1 do
        table.insert(waterTiles, {name = tile_type, position={x,y+i}})
    end
	
	-- Top right to Bottom right
	x = global.plot_table[plot_number]["inner_corners"]["top_right"][1]
	y = global.plot_table[plot_number]["inner_corners"]["top_right"][2]
	
    for i=0,distance,1 do
        table.insert(waterTiles, {name = tile_type, position={x,y+i}})
    end	
	
	surface.set_tiles(waterTiles, false)
end
Any help is greatly appreciated!

Re: Problem with set_tiles(tiles, correct_tiles)

Posted: Fri Mar 17, 2017 12:29 pm
by Klonan
That's just the tile correction logic for you...

The water needs a grass tile to border it, so i suggest just setting a grass perimeter around both sides of the water you set

Re: Problem with set_tiles(tiles, correct_tiles)

Posted: Sat Mar 18, 2017 6:27 am
by Maniah
Putting 4 grass tiles in every direction around the water did the trick.

Thank you!