bad arguement #-1 to 'set_tiles' (number expected, got tabl

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:

bad arguement #-1 to 'set_tiles' (number expected, got tabl

Post by Maniah »

I'm trying to create a "moat" around a certain area after the user clicked on a button.

Code: Select all

function plot_create_moat(event, plot_number)
	DebugPrint("Creating moat for plot " .. plot_number )
	local player = game.players[event.element.player_index]
	local surface = player.surface
    
	local waterTiles = {}
	local watertType = "water"
	local x = 0
	local y = 0
	local distance = 0
	
	distance = global.plot_table[plot_number]["inner_corners"]["top_right"][1] - global.plot_table[plot_number]["inner_corners"]["top_left"][1]
	DebugPrint("distance " .. distance)
	y = global.plot_table[plot_number]["inner_corners"][2]
	
    for i=0,distance,1 do
        table.insert(waterTiles, {name = watertType, position={x+i,y}})
    end
	
	DebugPrint(table_to_string(event))
	
	surface.set_tiles(waterTiles)
end
The last line of the function gives:
bad arguement #-1 to 'set_tiles' (number expected, got table)
I can use this code with the on_chunk_generated, but can't get it to work with the click.

Any ideas?

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

Re: bad arguement #-1 to 'set_tiles' (number expected, got tabl

Post by Klonan »

Code: Select all

y = global.plot_table[plot_number]["inner_corners"][2]
What is the value of this?

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

Re: bad arguement #-1 to 'set_tiles' (number expected, got tabl

Post by Maniah »

Klonan wrote:

Code: Select all

y = global.plot_table[plot_number]["inner_corners"][2]
What is the value of this?
Yep, that was it, the value was invalid here.

Thank you!

Post Reply

Return to “Modding help”