The tile language · guide

Things and layers

An element is a generator, and there are two kinds: a thing makes one solid on its own, and a layer reads the scene so far. A thing can be passed by name.

The result

The tile this source builds, from above
dharmatiles version="1.0.0"

// A thing passed by name.  `stand` holds a thing in `piece`: a pebble unless the caller says
// otherwise.  It puts one on the ground and scatters three more, so the same recipe draws a
// pebble stand and, called with `piece=boulder`, a boulder stand.
let stand {
    param piece pebble
    stack {
        piece at="(0.3sq, 0.5sq)"
        scatter count=3 { piece }
    }
}

tile size="1x1" seed=12 {
    stack {
        base
        dirt
        stand
        stand piece=boulder
    }
}
One definition, two stands: stand holds a thing in piece, a pebble by default, and the second call passes a boulder.

Say it plainly

Every element makes something, and it is one of two kinds. A thing is given its controls and a seed and makes one solid, with nothing else to look at: a rock, a stone, a boulder, a pebble, a flower, a tree, and a let whose body is one of them written bare. A layer also reads what the stack has built so far: dirt, ground, water and floors paint the ground, and a scatter, a wall or a cliff place their things on it.

Because a thing needs nothing but its controls and a seed, it can be handed around by name. A definition says param leaf pebble, uses leaf like an element, and the caller says which thing with leaf=boulder. A layer can be handed around too, param ground dirt and ground=water, but only into the stack, where it is used as an entry. Placing a thing makes it a layer, and nothing makes a layer a thing: a thing fits wherever a layer is wanted, and a layer never fits where a thing is. The program says so where it is written.

The rules

An element is a thing or a layer

The element schema says which, once, and the element pages say it under Kind. A thing is what a scatter may hold and what at= places on its own; every other element is a layer. A stack is always a layer, whatever it holds. A let names a thing only when its body is one entry written bare, an unplaced thing (let oak { tree … }; at= makes a placed thing a layer); anything else is a layer. Naming a stack of one thing is therefore a layer, and the bare form is the one way to name a thing.

KindTakesElements
thingits controls and a seedrock, stone, boulder, pebble, flower, tree, and a let whose body is one of them written bare, unplaced
layerits controls, a seed and the scene so fareverything else: dirt, ground, water, floor, scatter, grass, reeds, wall, cliff, a stack, and every other definition

These are two more kinds, checked before anything is built as lengths and angles are, by the same fit rule (kinds).

A param can hold a thing, and the caller passes it by name

A param holds a thing when its default names one, or when the definition writes it as an entry or as a scatter's child. The caller passes another thing by its name, an element or a let of one bare thing, written bare. Inside the definition the param's name calls the thing it holds, so one recipe serves every thing handed to it:

dharmatiles version="1.0.0"

let stand {
    param piece pebble
    stack {
        piece at="(0.3sq, 0.5sq)"
        scatter count=3 { piece }
    }
}

let boulder-ish { boulder }

tile size="1x1" seed=12 {
    stack {
        base
        dirt
        stand                          // its pebble
        stand piece=boulder            // an element
        stand piece=boulder-ish        // a definition of one thing
    }
}

A param with no default must be given by the caller, as every param must, and must say what it holds with kind= (below). A thing param is a plain name, and not the name of an element or of a definition (it would call that instead). A definition that holds itself through a param is the same loop as one that calls itself (dt::loop): a thing never makes a thing that makes another.

A param can hold a layer, and a place word passes through it

A param holds a layer when its default names one (param ground dirt), when kind=layer says so, or when a caller passes one to a param that holds one. The caller passes a built-in layer (water), a part (lawn) or a thing (placing it makes it a layer), written bare. A layer param can only be used as a stack entry, and a place word passes through to it as it does on a part call: shore ground=lawn at=bank puts the lawn in the region bank, and a place written on the entry (ground at=bank) holds the same way. Its properties are read as if written on what was passed, once the call says which it is, as a thing param's are.

dharmatiles version="1.0.0"

let lawn { stack { dirt; grass } }

let shore {
    param ground dirt
    stack {
        ground
    }
}

tile size="1x1" seed=7 {
    line edge { through "(0.5sq, 0sq)" "(0.5sq, 1sq)" }
    region bank { boundedBy edge; fill "(0.9sq, 0.5sq)" }
    stack {
        base
        shore ground=lawn at=bank
    }
}

Because the stack is read as the param filled it, the checks that read a whole stack run on it at the call, and point at the argument the caller wrote: a layer that reads what the stack does not make, or that is listed before what it needs, is dt::order or dt::plan at ground=… in the call.

A param's kind can be written: kind=

A param is a name of a kind: a length, an angle, a plain number, a thing or a layer. The kind is settled once, at the param, and never from where the param is used. kind= says it: param ground kind=layer, param leaf kind=thing, param reach kind=length. With no kind=, it is the kind of its default: param n 3 is a plain number, param w "5dmm" a length, param leaf pebble a thing. The words are the kinds' own (kinds).

Being a name, a param goes anywhere a let of its kind may: as a control's whole value (count=n), in a formula (count="n + 1"), and, for a thing or a layer, as an entry. Each use is checked against its kind where it is written, the default and every caller's argument against it at the call, and a disagreement is dt::type (or dt::unit for a number missing its unit) in the words of every kind mistake: rock size=n with param n 3 says that n is a plain number and rock size wants a length.

dharmatiles version="1.0.0"

let pile {
    param leaf kind=thing
    param reach kind=length "3dmm"
    param extra 2
    stack {
        scatter count="extra + 1" { leaf size=reach }
    }
}

tile size="1x1" seed=2 {
    stack {
        base
        dirt
        pile leaf=pebble reach="2dmm"
        pile leaf=pebble extra=4
    }
}

A param with no kind= and a default that is no number, thing or layer, or no default at all, is dt::kind, saying to write kind=: the program does not read a kind off the way the param is used. A kind= that is no kind a param holds (kind=region) is dt::kind too.

Properties written where a thing is used apply over its own

The properties written on the entry that calls a thing param, piece size="1dmm .. 2dmm", are the thing's own controls, read as if they were written on the thing itself. The one written there wins; what is not written there is the thing's own default (for a definition, its params' defaults). A property is checked exactly as it is on the thing itself, once the call says which thing it is: its unit and kind (piece size=5 has no unit, as pebble size=5 has none), its range, its words, a control the thing does not take, each refused with the same code and words, at the line where it is written in the definition. A group's controls are written the same way, as lines under the entry (piece { crown width="20dmm" } for a tree).

A param of the definition written as one of those controls' value (piece size=s) is checked against what the control takes, by the param's kind, where it is written: s a length fits size, and piece buried=s as well (a length where a share is wanted) is refused there. The caller's value (stand s=5) is checked against the param's kind at the call, however many definitions pass s on, and the control holds the value to its own range when it reads it.

The call that passes the thing passes a name and nothing else: stand piece=boulder cannot reach into the boulder. A thing is tuned where it is used, so two uses of one param in one definition may tune it twice. A thing's own seed is the call path's, like every entry's (seeds): two definitions that take the same thing draw it differently, and an entry written beside another does not move its draw.

dharmatiles version="1.0.0"

let stand {
    param piece pebble
    stack {
        piece size="1dmm .. 2dmm" at="(0.3sq, 0.5sq)"
        piece size="2dmm .. 3dmm" at="(0.6sq, 0.5sq)"
    }
}

tile size="1x1" seed=3 {
    stack {
        base
        dirt
        stand
    }
}

A scatter holds several things by weight

A scatter's children are a list of things, and each one placed picks its child by weight=. A child may be a thing param, and a definition of one thing, as well as an element. This is as far as the language goes: a thing is written once, passed by name or written as a child, or one of several weighted children. It is never a thing that returns a thing.

dharmatiles version="1.0.0"

let pile {
    param bit pebble
    stack {
        scatter count=6 {
            bit weight=5
            rock size="3dmm .. 5dmm" weight=1
        }
    }
}

tile size="1x1" seed=5 {
    stack {
        base
        dirt
        pile bit=stone
    }
}

A layer, a number or a nothing where a thing belongs is refused at the line

The kind is checked where the value is written, with what to write instead (dt::type):

stand piece=dirt      // `dirt` is a layer, and `stand piece` wants a thing
stand piece=3         // `3` is a plain number, and `stand piece` wants a thing
bank ground=3         // `3` is a plain number, and `bank ground` wants a layer
rock size=boulder     // `boulder` is a thing, and `rock size` wants a length

A name that is no element and no definition is dt::unknown-element, a thing param left without a value dt::missing-control, and a layer written as a scatter's child dt::scatter naming its kind: dirt is a layer, and a scatter wants a thing. A part whose one entry is placed is a layer too, so scatter count=4 {{ corner-rock }} with rock at="(0.1sq, 0.1sq)" in corner-rock says corner-rock is a layer. A param is one kind: one used as a thing and as the value of a control, or as the value of two controls that are not alike (a length and a share), is dt::type too, at the use, saying what it is and what wants it.

The editor draws a thing on its own, with a strip of draws and the room it takes: one thing alone.

Errors this page explains

  • dt::kind A parameter's kind is not a kind a parameter holds, or nothing says what it holds The rule

Next

Next: overhang and the gate, what every build is checked against before it is written.