Element · the document

let

A name for a value. let adds a name; override replaces a $ name, such as one of the library's heights, for its block. A $ name is read from the context every formula is called with; a plain name is read where it was written.

Writing it

dharmatiles version="1.0.0"

tile size="1x1" seed=31 {
    let knollTop  "$groundHeight + 4dmm"            // a plain name, this tile's own
    let hump      "$groundHeight + [1dmm .. 2dmm]"  // a range: a little rise, its height left free
    let $treeLine "40dmm"                           // a $ name: in the context, read by what is called below
    override $waterBedHeight "0.8dmm"               // deeper water, everywhere on this tile
    stack { base; dirt { pin top="knollTop" at=center } }
}

A value is an expression: numbers with their units, plain and $ names, $x and $y (squares), $bottom (the surface under a body), + - * /, a range in brackets [a .. b] anywhere, and the functions sin cos (of an angle), abs, min, max, clamp and smooth. Trigonometry is computed in the program, so a build gives the same bits on every machine.

Reference

Library heightValueMeaning
$waterBedHeight0.4dmmThe bottom of standing water: two print layers.
$waterSurfaceHeight2.6dmmCalm water.
$waterEdgeHeight$waterSurfaceHeight + 0.6dmm * cos(720deg * ($x - $y))Water at a tile edge: two waves a square, so water tiles butt any way round.
$dirtEdgeHeight3.4dmmWhere dirt meets a tile edge.
$groundHeight5dmmOpen land.
$floorHeight7.4dmmA built floor's top.
$floorEdgeHeight$floorHeightWhere a built floor meets a tile edge: flush.
$shortWallHeight16.55dmmHalf the wall top.
$wallHeight33.1dmmThe standard wall top.
$tallWallHeight72.3dmmThe tall wall top.

They come from library/parts/heights.dtile, and every tile sees them without a use line.

Notes

Two kinds of name. A $ name is read from the context: the library installs its heights at the root, an element sets $x $y $d $a $bottom $region at each point it builds, and let $name installs one of your own for its block. A plain name (let knollTop …, a definition's param) is declared once, where it is written, and never passed to a definition you call. let $name on a name the context already has is refused (dt::name) and the message offers override; override of a name nothing installed, or of one an element sets, is refused. A plain name that is a word of the language (x y d a parent, a function, a weighting or a unit) is refused too. let and override work in any block, such as scatter { override $treeLine "30dmm"; tree … }, and hold for that block and everything called from it.

An override reaches library expressions. A $ name is read where it is used, so overriding $waterSurfaceHeight at the top of a tile moves $waterEdgeHeight with it. An override of a name that does not exist is refused, with a nearby name if there is one, so a misspelt override is caught instead of doing nothing. Overriding an edge height means the tile no longer meets standard tiles without a step. dharmatiles check --explain lists each override (override $waterBedHeight 0.4dmm → 0.8dmm).

Kinds. A length carries its unit (4dmm), an angle deg, and a count or a fraction is a plain number; the kinds are checked before any build. $x and $y are squares counted, plain numbers, so $groundHeight + $x is refused (dt::type); scale them with a length or inside sin or cos, as the tide does. A range is a set: [0dmm .. 1dmm] - [0dmm .. 1dmm] is [-1dmm .. 1dmm]. See units and kinds.

Seen from the language

The guide pages that use let: The tile document, Values and ranges, Names.