Area.Tile module

Tools for working with tiles.

A tile represents a 1 unit2 on a surface in Factorio.

See also

Usage

local Tile = require('__stdlib__/stdlib/area/tile')

Functions

from_position() Get the tile position of a tile where the given position resides.
to_area() Converts a tile position to the area of the tile it is in.
adjacent(surface, position[, diagonal=false][, tile_name]) Creates an array of tile positions for all adjacent tiles (N, E, S, W) OR (N, NE, E, SE, S, SW, W, NW) if diagonal is set to true.
get_data(surface, tile_pos[, default_value]) Gets the user data that is associated with a tile.
set_data(surface, tile_pos, value) Associates the user data to a tile.

Functions

# from_position()

Get the tile position of a tile where the given position resides.

See also:
# to_area()

Converts a tile position to the area of the tile it is in.

See also:
# adjacent(surface, position[, diagonal=false][, tile_name])

Creates an array of tile positions for all adjacent tiles (N, E, S, W) OR (N, NE, E, SE, S, SW, W, NW) if diagonal is set to true.

Parameters:
  • surface : (LuaSurface) the surface to examine for adjacent tiles
  • position : (LuaTile.position) the tile position of the origin tile
  • diagonal : (boolean) whether to include diagonal tiles (default: false)
  • tile_name : (string) whether to restrict adjacent tiles to a particular tile name (example: “water-tile”) (optional)
Returns:
# get_data(surface, tile_pos[, default_value])

Gets the user data that is associated with a tile.

The user data is stored in the global object and it persists between loads.

Parameters:
  • surface : (LuaSurface) the surface on which the user data is looked up
  • tile_pos : (LuaTile.position) the tile position on which the user data is looked up
  • default_value : (Mixed) the user data to set for the tile and returned if it did not have user data (optional)
Returns:
  • (nil or Mixed) the user data OR nil if it does not exist for the tile and no default_value was set
# set_data(surface, tile_pos, value)

Associates the user data to a tile.

The user data will be stored in the global object and it will persist between loads.

Parameters:
  • surface : (LuaSurface) the surface on which the user data will reside
  • tile_pos : (LuaTile.position) the tile position of a tile that will be associated with the user data
  • value : (nil or Mixed) the user data to set OR nil to erase the existing user data for the tile
Returns:
  • (nil or Mixed) the previous user data associated with the tile OR nil if the tile had no previous user data