Skip to main content
Version: TEdit 5

Scripting Guide

TEdit 5 includes a built-in scripting engine for automating world edits. Write scripts in JavaScript (Jint) or Lua to batch-process tiles, search worlds, fill areas, and more.

Basics

Scripts run with full access to the loaded world data. The Scripting sidebar provides a code editor with syntax highlighting, script management, and an output log.

Hello World

log.print("Hello from TEdit scripting!");
log.print(`World: ${world.title} (${world.width}x${world.height})`);
log.print("Hello from TEdit scripting!")
log.print("World: " .. world.title)

Common Recipes

Replace tiles in selection

if (!selection.isActive) {
log.error("Select an area first!");
}

const from = metadata.tileId("Dirt Block");
const to = metadata.tileId("Stone Block");
const count = batch.replaceTileInSelection(from, to);
log.print(`Replaced ${count} tiles`);

Fill a rectangle with walls

geometry.setWalls(metadata.wallId("Stone Wall"), 100, 200, 50, 30);
log.print("Filled 50x30 area with stone walls");

Find all chests containing a specific item

const chests = chests.findByItemName("Zenith");
for (const c of chests) {
log.print(`Found at (${c.x}, ${c.y}): ${c.name || "Chest"}`);
finder.addResult("Zenith Chest", c.x, c.y, "chest");
}
log.print(`Found ${chests.length} chests with Zenith`);

Draw a circle of tiles

const points = geometry.fillEllipse(500, 300, 25, 25);
const tileType = metadata.tileId("Glass Block");
for (const p of points) {
tile.setType(p.x, p.y, tileType);
}
log.print(`Placed ${points.length} glass tiles`);

Clear all of a tile type

const count = batch.clearTilesByType(metadata.tileId("Sand Block"));
log.print(`Cleared ${count} sand blocks`);

Show progress for long operations

const total = world.width * world.height;
let processed = 0;

batch.forEachTile((x, y) => {
// ... your logic here ...
processed++;
if (processed % 100000 === 0) {
log.progress(processed / total);
}
});
log.progress(1.0);
log.print("Done!");

API Reference

tile — Tile Read/Write

MethodDescription
isActive(x, y) → boolCheck if tile is active
getTileType(x, y) → intGet tile type ID
getWall(x, y) → intGet wall type ID
getPaint(x, y) → intGet tile paint color
getWallPaint(x, y) → intGet wall paint color
getLiquidAmount(x, y) → intGet liquid amount (0–255)
getLiquidType(x, y) → intGet liquid type (0=none, 1=water, 2=lava, 3=honey)
getFrameU(x, y) → intGet sprite frame U
getFrameV(x, y) → intGet sprite frame V
getSlope(x, y) → stringGet slope type
getWire(x, y, color) → boolCheck wire (1=red, 2=blue, 3=green, 4=yellow)
setActive(x, y, active)Set tile active state
setType(x, y, type)Set tile type (activates tile)
setWall(x, y, wallType)Set wall type
setPaint(x, y, color)Set tile paint color
setWallPaint(x, y, color)Set wall paint color
setLiquid(x, y, amount, type)Set liquid amount and type
setWire(x, y, color, enabled)Set wire state
setSlope(x, y, slope)Set slope (None, HalfBrick, SlopeTopRight, etc.)
setFrameUV(x, y, u, v)Set sprite frame coordinates
clear(x, y)Reset tile to empty
copy(fromX, fromY, toX, toY)Copy tile properties

batch — Bulk Operations

MethodDescription
forEachTile(callback)Iterate entire world — callback(x, y)
forEachInSelection(callback)Iterate selection — callback(x, y)
findTiles(predicate) → [{x, y}]Find tiles matching predicate (max 10,000)
findTilesByType(type, anchorOnly?) → [{x, y}]Find by type; anchorOnly returns sprite origins
findTilesByWall(wallType) → [{x, y}]Find by wall type (max 10,000)
replaceTile(from, to) → intReplace all tiles of one type
replaceTileInSelection(from, to) → intReplace in selection only
replaceWall(from, to) → intReplace all walls of one type
clearTilesByType(type) → intClear all tiles of type

geometry — Shapes

MethodDescription
line(x1, y1, x2, y2) → [{x, y}]Line coordinates
rect(x, y, w, h) → [{x, y}]Rectangle outline
ellipse(cx, cy, rx, ry) → [{x, y}]Ellipse outline
fillRect(x, y, w, h) → [{x, y}]Filled rectangle
fillEllipse(cx, cy, rx, ry) → [{x, y}]Filled ellipse
setTiles(type, x, y, w, h)Fill rect with tiles
setWalls(type, x, y, w, h)Fill rect with walls
clearTiles(x, y, w, h)Clear tiles in rect

selection — Selection

Property/MethodDescription
isActive → boolWhether selection is active
x, y, width, heightSelection bounds
left, top, right, bottomSelection edges
set(x, y, w, h)Create selection
clear()Remove selection
contains(x, y) → boolPoint-in-selection test

chests — Chest Inventory

MethodDescription
count → intTotal chests
getAll() → [...]All chests
getAt(x, y) → {...}Chest at position
findByItem(id) → [...]Find by item ID
findByItemName(name) → [...]Find by item name
setItem(x, y, slot, id, stack, prefix)Set slot contents
clearItem(x, y, slot)Clear slot
addItem(x, y, id, stack, prefix) → boolAdd to first empty slot

signs — Sign Text

MethodDescription
count → intTotal signs
getAll() → [...]All signs
getAt(x, y) → {...}Sign at position
setText(x, y, text)Update text

npcs — Town NPCs

MethodDescription
count → intTotal NPCs
getAll() → [...]All NPCs with positions
setHome(name, x, y)Set NPC home

world — World Metadata (read-only)

PropertyDescription
width, heightWorld size in tiles
titleWorld name
seedWorld seed
spawnX, spawnYSpawn coordinates
surfaceLevel, rockLevelLayer boundaries

metadata — Game Data Lookup

MethodDescription
tileId(name) → intTile ID by name (-1 if not found)
wallId(name) → intWall ID by name
itemId(name) → intItem ID by name
tileName(id) → stringTile name by ID
wallName(id) → stringWall name by ID
itemName(id) → stringItem name by ID
allTiles(), allWalls(), allItems()All definitions

log — Output

MethodDescription
print(msg)Log info
warn(msg)Log warning
error(msg)Log error
progress(value)Update progress bar (0.0–1.0)

finder — Find Sidebar Integration

MethodDescription
clear()Clear results
addResult(name, x, y, type, extraInfo?)Add result (max 1,000)
navigate(index)Navigate to result
navigateFirst()Go to first result

tools — UI Tools

MethodDescription
listTools() → [string]Available tool names
copySelection()Copy selection to clipboard
getTilePickerTile() → intCurrent tile picker value
getTilePickerWall() → intCurrent wall picker value
setTilePickerTile(type)Set tile picker
setTilePickerWall(type)Set wall picker