Question about on_player_selected_area

Place to get help with not working mods / modding interface.
Sunnova
Fast Inserter
Fast Inserter
Posts: 169
Joined: Mon May 16, 2016 12:10 pm
Contact:

Question about on_player_selected_area

Post 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.
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Question about on_player_selected_area

Post by prg »

Does the selection-tool's selection_mode contain "any-tile"?
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Sunnova
Fast Inserter
Fast Inserter
Posts: 169
Joined: Mon May 16, 2016 12:10 pm
Contact:

Re: Question about on_player_selected_area

Post by Sunnova »

prg wrote:Does the selection-tool's selection_mode contain "any-tile"?

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

Return to “Modding help”