But when I set it to true, I get a different result every time. An example:
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