Tile Object Documentation

Overview

The Tile object in GrowSoft represents a single block (tile) in a world.
It provides access to tile properties, foreground/background items, and data manipulation.
Most methods are used with the colon operator (tile:getTileID()).


Tile Position

tile:getPosX() -- Returns the X coordinate of the tile.
tile:getPosY() -- Returns the Y coordinate of the tile.
ℹ️

Coordinate System

These coordinates represent the tile’s position within the world grid, starting from (0, 0) in the top-left corner.


Tile Structure

tile:getTileID() -- Returns the foreground item ID of the tile.
tile:getTileForeground() -- Returns the foreground item ID (same as getTileID).
tile:getTileBackground() -- Returns the background item ID of the tile.

Tile Data

tile:getTileData(property) -- Gets a specific data property from a tile.
tile:setTileDataInt(property, value) -- Sets a specific integer data property on a tile.
ℹ️

Data Interaction

These functions allow interaction with tile-specific data fields, such as growth state, tree fruit count, or lock ownership. After modifying data using setTileDataInt, call world:updateTile(tile) to refresh visuals.


Tile Item Interaction

tile:getTileItem() -- Returns the item object associated with the tile's foreground.

Tile Flags

Manage tile visual and behavioral flags like rotation, paint colors, and more:

tile:getFlags() -- Returns the tile's current flags as a number.
tile:setFlags(flags) -- Sets the tile's flags.
⚠️

Update Required

After setting flags, call world:updateTile(tile) to apply visual changes.

Available Flag Constants

TILE_FLAG_HAS_EXTRA_DATA = bit.lshift(1, 0)
TILE_FLAG_HAS_PARENT = bit.lshift(1, 1)
TILE_FLAG_WAS_SPLICED = bit.lshift(1, 2)
TILE_FLAG_WILL_SPAWN_SEEDS_TOO = bit.lshift(1, 3)
TILE_FLAG_IS_SEEDLING = bit.lshift(1, 4)
TILE_FLAG_FLIPPED_X = bit.lshift(1, 5)
TILE_FLAG_IS_ON = bit.lshift(1, 6)
TILE_FLAG_IS_OPEN_TO_PUBLIC = bit.lshift(1, 7)
TILE_FLAG_BG_IS_ON = bit.lshift(1, 8)
TILE_FLAG_FG_ALT_MODE = bit.lshift(1, 9)
TILE_FLAG_IS_WET = bit.lshift(1, 10)
TILE_FLAG_GLUED = bit.lshift(1, 11)
TILE_FLAG_ON_FIRE = bit.lshift(1, 12)
TILE_FLAG_PAINTED_RED = bit.lshift(1, 13)
TILE_FLAG_PAINTED_GREEN = bit.lshift(1, 14)
TILE_FLAG_PAINTED_BLUE = bit.lshift(1, 15)

Bitwise Operations

Use Lua’s bit library for combining and checking flags with bitwise operations!

Example: Paint Bucket Colors

local world = getWorld(1)
local tile = world:getTile(1, 1)
local tile_flags = tile:getFlags()
 
-- Check if tile is painted red
if bit.band(tile_flags, TILE_FLAG_PAINTED_RED) ~= 0 then
    print("Tile is painted red")
else 
    -- Add red paint to tile
    local new_flags = bit.bor(tile_flags, TILE_FLAG_PAINTED_RED)
    tile:setFlags(new_flags)
    print("Tile has been painted red")
    world:updateTile(tile)
end

Example: Toggle Tile On/Off

local flags = tile:getFlags()
if bit.band(flags, TILE_FLAG_IS_ON) ~= 0 then
    -- Turn off
    flags = bit.band(flags, bit.bnot(TILE_FLAG_IS_ON))
else
    -- Turn on
    flags = bit.bor(flags, TILE_FLAG_IS_ON)
end
tile:setFlags(flags)
world:updateTile(tile)
ℹ️

Common Use Cases

  • Paint Colors: Combine TILE_FLAG_PAINTED_RED, TILE_FLAG_PAINTED_GREEN, TILE_FLAG_PAINTED_BLUE for RGB colors
  • On/Off States: Perfect for switches, doors, and interactive blocks
  • Visual Effects: Control flipped, wet, fire, and glued states