Page 1 of 1
Set tiles
Posted: Tue Feb 28, 2017 10:26 am
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}})
Re: Set tiles
Posted: Tue Feb 28, 2017 10:31 am
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}}}
Re: Set tiles
Posted: Tue Feb 28, 2017 10:42 am
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.
Re: Set tiles
Posted: Tue Feb 28, 2017 11:39 am
by darkfrei
I think it can be short, but with wrong position in table.
Re: Set tiles
Posted: Tue Feb 28, 2017 1:52 pm
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
Re: Set tiles
Posted: Tue Feb 28, 2017 2:00 pm
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.
Re: Set tiles
Posted: Tue Feb 28, 2017 2:11 pm
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)
Re: Set tiles
Posted: Tue Feb 28, 2017 2:20 pm
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.
Re: Set tiles
Posted: Wed Mar 01, 2017 5:36 am
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
without "=..." seem to accept shorthand.
Re: Set tiles
Posted: Wed Mar 01, 2017 8:19 am
by darkfrei
vtx wrote:
without "=..." seem to accept shorthand.
If it have right position.
Re: Set tiles
Posted: Wed Mar 01, 2017 9:00 am
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.