The result

dharmatiles version="1.0.0"
tile size="2x2" seed=31 {
let knollTop "$groundHeight + 4dmm" // a plain name: this tile's own
let $treeLine "40dmm" // a $ name: the context, read by whatever is called below
override $waterBedHeight "0.8dmm" // deeper water, everywhere on this tile
stack {
base
dirt { pin top="knollTop" at=center }
scatter count=2 {
override $treeLine "30dmm" // for this block only
tree top="$bottom + $treeLine"
}
}
}
$ name read by what is built below it, and a deeper water bed than the library gives.Say it plainly
A $ name such as $groundHeight is a number the surroundings supply: the library installs its heights, and each element sets the names that say where it is working. A plain name such as knollTop is yours, declared once with let.
let $name adds a name for a block, and override $name changes one for that block and everything called from it. Neither can touch a name an element sets, because that would change where it is.
The rules
A name is a $ name or a plain name
A name is one of two kinds, and the $ says which.
| Kind | Written | Where its value comes from |
|---|---|---|
$ names | $x, $d, $bottom, $region, $groundHeight | The context: a record of $ names that every formula is called with. The library installs its heights in it, an element sets the position names at each point it works out, and a let $name adds one of your own. Whatever calls a formula or a definition passes its context on, changed only where it says so. |
| plain names | knollTop, a definition's length | The place they were written: a tile's own let, a definition's param. They are never passed to a definition you call. |
The two are separate namespaces: a parameter called length never hides anything with a $, and $high is a fine name though high is a weighting.
let adds a name and override replaces one
| Written | Does | Error when |
|---|---|---|
let $treeLine "40dmm" | puts a new $ name in the context, for everything in this block | the context already has it: use override (dt::name) |
override $groundHeight "6dmm" | replaces a $ name for this block and everything called from it; when the block ends the old value is back | no caller installed it (the message offers the nearest name), or an element sets it itself ($x $y $d $a $bottom $region $tile) |
let knollTop "$groundHeight + 4dmm" | declares a plain name, once | the name is already declared, or is a word of the language |
let and override work at the top of a tile and inside any block (scatter { override $treeLine "40dmm"; tree … }), and take effect for the rest of that block, the entry they sit in included. A let holds a formula, read where it is used: let $floorEdgeHeight "$floorHeight" follows an override $floorHeight made below it. A $ name read where no caller installed it is dt::unknown-name at that spot, and check works out which names each part reads at each place it is called, so a part that reads a name its caller does not have is refused at that call. Plain names are camelCase, since a hyphen would read as subtraction (dt::name).
The library installs its heights as $ names
The library's heights come from library/parts/heights.dtile and every file sees them without a use line, as $ names in design millimetres above zero (the top of the base):
let $waterBedHeight "0.4dmm" // the bottom of standing water: two print layers
let $waterSurfaceHeight "2.6dmm" // calm water
let $waterEdgeHeight "$waterSurfaceHeight + 0.6dmm * cos(720deg * ($x - $y))" // water at a tile edge: two waves a square
let $dirtEdgeHeight "3.4dmm" // where dirt meets a tile edge
let $groundHeight "5dmm" // open land
let $floorHeight "7.4dmm" // a built floor's top
let $floorEdgeHeight "$floorHeight" // where a built floor meets a tile edge: flush
let $shortWallHeight "16.55dmm" // half the wall top
let $wallHeight "33.1dmm" // the standard wall top
let $tallWallHeight "72.3dmm"
Beside them an element sets the names a formula may read at each point it works out:
| Name | Is | Kind |
|---|---|---|
$x, $y | where the point is in the tile, in squares from its north-west corner: x($tile, sq) and y($tile, sq) | plain number |
$d | how far in from the edge of the thing's own region: 0 wherever deepest in the interior, 1 right at the edge | plain fraction |
$a | how far round the region: 0 at east, turning towards the south as the page reads (a quarter is straight down), 1 a full turn | plain fraction |
$bottom | what the thing stands on at that point: the surface below it in the stack (the base for a first dirt, the dirt under a second, the ground at a tree's foot, a water's bed) | length |
$region | the region of the thing being built (regions) | region |
$tile | the whole tile, the root region | region |
A body (dirt, water, flagstones, planks, cliff) sets all of these at each point of its region. A tree sets all of these at each branch tip, with $region its own disc round the trunk and $bottom the ground at its foot; every other element sets $region. check knows this before any build: reading a name the element does not set is dt::unknown-name at the exact spot, with what the element does set. Because $x and $y are the tile's, neighbouring tiles' heights meet, like the water's shared tide. Local position in a region is one call away: x($region, sq).
A name must be declared or set where it is read
A height, a $ name or a place that nothing declares or sets is refused, with the nearest name: nothing installed `$groundHeihgt` where this is read, with the help did you mean $groundHeight?
A plain name may not be a word of the language
A plain name (a let, a param) may not be a word of the language; it is a dt::name error that names the word and its kind.
| coordinates | x y d a parent |
|---|---|
| functions | sin cos abs min max clamp smooth point polar |
| weightings | flat low high bell peak ends steps mix |
| units | sq mm in layer deg rad pi dmm |
let a 3 is refused, with help to choose another name. Node names (line, layer in a printer file) are not plain names, so they keep theirs.
Errors this page explains
dt::unknown-nameNothing declares or sets that name The ruledt::nameA plain name is declared twice or is a word of the language The rule
Next
Next: heights, where the library’s names are used.