Area.Chunk module

For working with chunks.

A chunk represents a 32 tile2 on a surface in Factorio.

See also

Usage

local Chunk = require('__stdlib__/stdlib/area/chunk')

Functions

from_position() Gets the chunk position of a chunk where the specified position resides.
to_position() Gets the top_left position from a chunk position.
to_area(pos) Gets the area of a chunk from the specified chunk position.
get_data(surface, chunk_pos[, default_value]) Gets the user data that is associated with a chunk.
set_data(surface, chunk_pos, value) Associates the user data to a chunk.

Functions

# from_position()

Gets the chunk position of a chunk where the specified position resides.

See also:
# to_position()

Gets the top_left position from a chunk position.

See also:
# to_area(pos)

Gets the area of a chunk from the specified chunk position.

Parameters: Returns:
# get_data(surface, chunk_pos[, default_value])

Gets the user data that is associated with a chunk.

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
  • chunk_pos : (ChunkPosition) the chunk position on which the user data is looked up
  • default_value : (Mixed) the user data to set for the chunk and returned if the chunk had no user data (optional)
Returns:
  • (nil or Mixed) the user data OR nil if it does not exist for the chunk and if no default_value was set
# set_data(surface, chunk_pos, value)

Associates the user data to a chunk.

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
  • chunk_pos : (ChunkPosition) the chunk position to associate with the user data
  • value : (nil or Mixed) the user data to set OR nil to erase the existing user data for the chunk
Returns:
  • (nil or Mixed) the previous user data associated with the chunk OR nil if the chunk had no previous user data