Set tiles

Place to get help with not working mods / modding interface.
Post Reply
vtx
Fast Inserter
Fast Inserter
Posts: 150
Joined: Tue Jun 28, 2016 9:48 am
Contact:

Set tiles

Post by vtx »

It's said to use this function as a batch. How the right way to do it ?

Code: Select all

set_tiles({"grass",{1,1}},{"grass",{2,2}},{"grass",{3,3}})

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Set tiles

Post by prg »

LuaSurface::set_tiles

Code: Select all

set_tiles{{name="grass",position={1,1}},{name="grass",position={2,2}},{name="grass",position={3,3}}}
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

vtx
Fast Inserter
Fast Inserter
Posts: 150
Joined: Tue Jun 28, 2016 9:48 am
Contact:

Re: Set tiles

Post by vtx »

I check the lua api I was thinking it's working same as position.

Both are valid : {1,1} or {x = 1, y = 1}

Explicit specification are required and no shorthand allowed for that function.

Thanks for clarification.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Set tiles

Post by darkfrei »

I think it can be short, but with wrong position in table.

Eliont
Burner Inserter
Burner Inserter
Posts: 19
Joined: Thu Feb 16, 2017 3:48 pm
Contact:

Re: Set tiles

Post by Eliont »

Emmm...
using them in cycle will not work?

Code: Select all

for x = 1,10 do
    for y = 1,10 do
        set_tiles({"grass",{x,y}})
    end
end

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Set tiles

Post by prg »

Eliont wrote:Emmm...
using them in cycle will not work?

Code: Select all

for x = 1,10 do
    for y = 1,10 do
        set_tiles({"grass",{x,y}})
    end
end
From LuaSurface::set_tiles:
Note: It is recommended to call this method once for all the tiles you want to change rather than calling it individually for every tile. As the tile correction is used after every step, calling it one by one could cause the tile correction logic to redo some of the changes, and it is also much performance heavy.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3699
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Set tiles

Post by DaveMcW »

Code: Select all

local tiles = {}
for x = 1,10 do
    for y = 1,10 do
      table.insert(tiles, {"grass",{x,y}}
    end
end
set_tiles(tiles)

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Set tiles

Post by prg »

DaveMcW wrote:

Code: Select all

local tiles = {}
for x = 1,10 do
    for y = 1,10 do
      table.insert(tiles, {"grass",{x,y}}
    end
end
set_tiles(tiles)
That still won't work without "name" and "position" as keys.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

vtx
Fast Inserter
Fast Inserter
Posts: 150
Joined: Tue Jun 28, 2016 9:48 am
Contact:

Re: Set tiles

Post by vtx »

prg wrote:
DaveMcW wrote:

Code: Select all

local tiles = {}
for x = 1,10 do
    for y = 1,10 do
      table.insert(tiles, {"grass",{x,y}}
    end
end
set_tiles(tiles)
That still won't work without "name" and "position" as keys.
Are you sure about that ?
There are 2 different type of function in lua api.

Code: Select all

can_place_entity{name=…, position=…, direction=…, force=…}
"=..." seem to be where you MUST use explicit specification

Code: Select all

find_entity(entity, position)
without "=..." seem to accept shorthand.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Set tiles

Post by darkfrei »

vtx wrote: without "=..." seem to accept shorthand.
If it have right position.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Set tiles

Post by prg »

vtx wrote:Are you sure about that ?

Code: Select all

/c game.player.surface.set_tiles{{name="grass", position={1,1}}}
Works.

Code: Select all

/c game.player.surface.set_tiles{{"grass", {1,1}}}
"Expected field name in tile set item."

Code: Select all

can_place_entity{name=…, position=…, direction=…, force=…}
is just short for

Code: Select all

can_place_entity({name=…, position=…, direction=…, force=…})
passing the table as the first argument. That's how "named" arguments are done in Lua. Now set_tiles expects a table of tables containing tile descriptions as its first argument. Those tables with tile descriptions apparently are required to contain "name" and "position" as keys.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

Post Reply

Return to “Modding help”