Page 1 of 1

Question about on_player_selected_area

Posted: Fri May 26, 2017 6:54 pm
by Sunnova
Trying to loop through a selected area, to see what the tiles are in the area I've seleted.

I'm getting the item fine, but not getting the tiles for the area I've selected. I've tried pairs and ipairs.

am I doing the tiles = event.tiles wrong? Thanks for any help.

Code: Select all

script.on_event(defines.events.on_player_selected_area, function(event)
  local player = game.players[event.player_index]
  local tiles = event.tiles
  local item = event.item
  player.print("item name " .. item)
  if item == "place-item" then
    for _,tile in ipairs(tiles) do
      player.print("tile name " .. tile.name)
    end
  end
end)
This is what I found online.

on_player_selected_area
Called after a player selects an area with a selection-tool item.

Contains
player_index :: uint: The player doing the selection.
area :: BoundingBox: The area selected.
item :: string: The item used to select the area.
entities :: array of LuaEntity: The entities selected.
tiles :: array of LuaTile: The tiles selected.


LuaTile

class LuaTile - sort
collides_with(layer) What type of things can collide with this tile?
name :: string [R] Prototype name of this tile.
prototype :: LuaTilePrototype [R]
position :: Position [R] The position this tile references.
hidden_tile :: string (optional) [R]
valid :: boolean [R] Is this object valid?
help() → string All methods, and properties that this object supports.
A single "square" on the map.

Re: Question about on_player_selected_area

Posted: Fri May 26, 2017 7:18 pm
by prg
Does the selection-tool's selection_mode contain "any-tile"?

Re: Question about on_player_selected_area

Posted: Fri May 26, 2017 7:47 pm
by Sunnova
prg wrote:Does the selection-tool's selection_mode contain "any-tile"?

it does now, many thanks, working just fine :)