Problem with set_tiles(tiles, correct_tiles)

Place to get help with not working mods / modding interface.
Post Reply
Maniah
Inserter
Inserter
Posts: 40
Joined: Thu Mar 24, 2016 4:31 am
Contact:

Problem with set_tiles(tiles, correct_tiles)

Post 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!

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5148
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Problem with set_tiles(tiles, correct_tiles)

Post 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

Maniah
Inserter
Inserter
Posts: 40
Joined: Thu Mar 24, 2016 4:31 am
Contact:

Re: Problem with set_tiles(tiles, correct_tiles)

Post by Maniah »

Putting 4 grass tiles in every direction around the water did the trick.

Thank you!

Post Reply

Return to “Modding help”