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/area/tile')

Functions

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.
from_position (position) Get the tile position of a tile where the given position resides.
get_data (surface, tile_pos[, default_value]) Gets the user data that is associated with a tile.
get_index (tile_pos) Calculates and returns a stable and deterministic integer ID of a tile from a given tile position.
set_data (surface, tile_pos, data) Associates the user data to a tile.
to_area (tile_pos) Converts a tile position to the area of the tile it is in.

Functions

# 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:
# from_position (position)

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

Parameters:
  • position : (Position) the position that resides somewhere in a tile
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
# get_index (tile_pos)

Calculates and returns a stable and deterministic integer ID of a tile from a given tile position.

The tile ID will not change once it is calculated, and every tile ID is unique to the chunk they are in and they may repeat across a surface.

Parameters: Returns:
  • (int) the tile ID
# set_data (surface, tile_pos, data)

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
  • data : (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
# to_area (tile_pos)

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

Parameters: Returns: