# Harlowe

Examples taken from the [Harlowe online documentation](https://twine2.neocities.org/)

{% hint style="warning" %}
Harlowe and Moontale have fundamentally different use-cases! This guide is not exhaustive - in particular, it does not cover Styling, Input, Transitions, and utility functions.
{% endhint %}

## Hooks vs. Render functions

In Harlowe, a Hook is a specific *instance* of content in a passage. A Hook can be hidden or shown at will, causing it to be inserted/removed from the passage text. A Hook name, when used in code, acts like a selector and is used to modify all Hooks with that name.

In contrast, Moontale render functions are a set of instructions for displaying content. Render functions can be combined with Changers, stored and retrieved like normal variables, and used in-line with other text as many times as desired. It is not possible to select and mutate text segments that have already been outputted; instead, use a variable to control what is outputted in a given block and call `reload()` to make the changes visible.

## Syntax

The following syntax is identical in both Harlowe and Moontale:

* `[[Passage]]`
* `[[Link->Target]]`
* `[[Target<-Link]]`
* `~~Strike through~~`
* `*Emphasis*`
* `**Strong emphasis**`
* `$variable`
* Special passage tags: `startup`, `header`, and `footer`

| Harlowe                                                                                                                             | Moontale                                                                                                                                                                                                           |
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `[[Label -> $target]]`                                                                                                              | `$Link(target)[Label]`                                                                                                                                                                                             |
| `//Italics//`                                                                                                                       | `*Italics*` or `_Italics_`                                                                                                                                                                                         |
| `''Bold''`                                                                                                                          | `**Bold**`or `__Bold__`                                                                                                                                                                                            |
| `<custom-tag>Text</custom-tag>`                                                                                                     | `$Style.custom_tag[Text]`                                                                                                                                                                                          |
| `\|foo)[Text]` or `[Text](foo\|`                                                                                                    | `$Name.foo[Text]`                                                                                                                                                                                                  |
| `\|foo>[Text]` or `[Text]<foo\|`                                                                                                    | `$Name.foo[Text] $foo`                                                                                                                                                                                             |
| `(show: ?foo)`                                                                                                                      | <p><code>$If(foo)\[ ... ]</code></p><p><code>{$ foo = true; Reload() $}</code></p>                                                                                                                                 |
| `?Passage`                                                                                                                          | `Passage.content` (a [Render Function](/concepts.md#render-functions))                                                                                                                                             |
| `?Page`, `?Sidebar`, `?Link`                                                                                                        | ⚠️ **Not supported**                                                                                                                                                                                               |
| `[==`                                                                                                                               | `[` - Content blocks are closed automatically                                                                                                                                                                      |
| `` `[[ ]]` ``                                                                                                                       | `<$ '[[ ]]' $>`                                                                                                                                                                                                    |
| ``` ``Single grave: ` `` ```                                                                                                        | `` Single grave: ` ``                                                                                                                                                                                              |
| `<$ $> {$ $}`                                                                                                                       | <p><code><$ '<$ $'..'> {$ $}' $></code></p><p>See <a href="/pages/-MYWq1v10kJduvZqjRaW#the-parser-is-dumb">The parser is dumb</a></p>                                                                              |
| <p> <code>\* Bulleted item</code></p><p>    <code>\*    Bulleted item 2</code></p><p>  <code>\*\* Indented bulleted item</code></p> | <p><code>\* Bulleted item</code></p><p><code>\* Bulleted item 2</code></p><p>    <code>\* Indented bulleted item</code></p>                                                                                        |
| <p><code>0. Numbered item</code></p><p>   <code>0. Numbered item 2</code></p><p> <code>0.0. Indented numbered item</code></p>       | <p><code>1. Numbered item</code></p><p><code>1. Numbered item 2</code></p><p>    <code>1. Indented numbered item</code></p>                                                                                        |
| `==>`, `=><=`, `<==>`, and `<==`                                                                                                    | `$Align.right[`, `$Align.center[`, `$Align.justify[`, and `$Align.left[`                                                                                                                                           |
| `===><=`, `=><=====` etc.                                                                                                           | <p>⚠️ <strong>Not supported</strong></p><p>You'd need custom tags for this</p>                                                                                                                                     |
| `\|==`, `=\|\|\|=` etc.                                                                                                             | <p>⚠️ <strong>Not supported</strong></p><p>You'd need custom tags for this</p>                                                                                                                                     |
| `# Heading`                                                                                                                         | `# Heading`                                                                                                                                                                                                        |
| <p><code>{ Single</code></p><p><code>line }</code></p><p><code>New line</code></p>                                                  | <p><code>Single</code> </p><p><code>line \</code></p><p><code>New line</code></p>                                                                                                                                  |
| <p><code>Single \</code></p><p><code>Line</code></p><p><code>\ text</code></p><p><code>New line</code></p>                          | <p><code>Single</code></p><p><code>Line</code></p><p><code>text \</code></p><p><code>New line</code></p>                                                                                                           |
| <p><code>(set: $foo to 5)</code></p><p><code>(put: 5 into $foo)</code></p>                                                          | `{$ foo = 5 $}`                                                                                                                                                                                                    |
| `(set: num-type $foo to 5)` and friends                                                                                             | <p>⚠️ <strong>Not supported</strong></p><p>May be possible using <a href="https://github.com/andremm/typedlua">Typed Lua</a></p>                                                                                   |
| `(set: _foo to 5)`                                                                                                                  | <p>⚠️ <strong>Not supported</strong></p><p>Use global <code>$foo</code> or <code>local foo</code> in code blocks</p>                                                                                               |
| `(move: $foo into $bar)`                                                                                                            | `{$ bar = foo; foo = nil $}`                                                                                                                                                                                       |
| `(print: $foo)`                                                                                                                     | `$foo` (but note the edge-cases!)                                                                                                                                                                                  |
| `(set: $foo to (print: $bar))`                                                                                                      | `$Name.foo[$bar]` or `{$ foo = function() Show(bar) end $}`                                                                                                                                                        |
| `(if: $legs is 8)`                                                                                                                  | `$If(legs == 8)`                                                                                                                                                                                                   |
| `(hidden:)`                                                                                                                         | `$If(false)` if you really need it - but you probably want to use `name`                                                                                                                                           |
| `(if: x is 5)[Show] (else:)[Hide] (else:)[Show]`                                                                                    | `$If(x == 5)[Show Show] $Else[Hide]`                                                                                                                                                                               |
| `(for: each _item, ...$array)`                                                                                                      | `$ForEach(array)` with `value` as the iterator, or `$ForEach(array, 'key', 'item')`                                                                                                                                |
| `(for: each _value, 2, 4, 6, 8)`                                                                                                    | `$ForEach{2, 4, 6, 8}`                                                                                                                                                                                             |
| `(for: _ingredient where it contains "petal", ...$reagents)`                                                                        | `$ForEach(reagents)[$If(string.find(value, 'petal') [ ... ]]`                                                                                                                                                      |
| `(for: each _i, ...(range:1,10))`                                                                                                   | `$Repeat(10)`                                                                                                                                                                                                      |
| `(either: "a", "b", "c")`                                                                                                           | `$Random('a', 'b', 'c')`🚧                                                                                                                                                                                         |
| `(either: ...$array)`                                                                                                               | `$Random(table.unpack(array))`🚧                                                                                                                                                                                   |
| `(cond: x is 1, "a", x is 2, "b")`                                                                                                  | `<$ {'a', 'b'}[x] $>`                                                                                                                                                                                              |
| `(cond: x is 'a', 1, x is 'b', 2)`                                                                                                  | `<$ {a = 1, b = 2}[x] $>`                                                                                                                                                                                          |
| ``(v6m:)[ \(`A`)/ ]``                                                                                                               | ``<$ '\(`A`)/' $>``                                                                                                                                                                                                |
| `(print: "**foo**")`                                                                                                                | See [Text output is not re-parsed](/conventions-and-caveats.md#text-output-is-not-re-parsed)                                                                                                                       |
| `(verbatim-print: ?hookName)`                                                                                                       | <p>⚠️ <strong>Not supported</strong></p><p>It may be possible to do this by overriding the output functions to convert tags into Markdown tokens</p>                                                               |
| `(enchant: 'gold', (text-colour: yellow))`                                                                                          | <p><code>$Enchant('gold', color.yellow)\[</code></p><p>Note the rules on <a href="/pages/-MYWq1v10kJduvZqjRaW#immutability">Immutability</a>; this must be done <em>before</em> the text you want to change 🚧</p> |
| `(enchant: ?ghost, (text-style: 'outline'))`                                                                                        | <p><code>{$ ghost = Style.outline $}</code></p><p>This must be done <em>before</em> using <code>ghost</code> as a changer. 🚧</p>                                                                                  |
| `(change: 'gold', (text-colour: yellow))`                                                                                           | <p>⚠️ <strong>Not supported</strong></p><p>It's not possible to change existing output</p>                                                                                                                         |
| `(enchant-in: ?frog, (text-colour: green))`                                                                                         | <p><code>$With{frog = Combine(frog, Color.green)}\[</code></p><p>🚧</p>                                                                                                                                            |
| `(print: (hooks-named:` `$companionType))`                                                                                          | `<$ _G[companionType] $>`                                                                                                                                                                                          |
| `(a: 'foo', 'bar')`                                                                                                                 | `{'foo', 'bar'}`                                                                                                                                                                                                   |
| `(dm: 'a', 1, 'b', 2)`                                                                                                              | `{a = 1, b = 2}`                                                                                                                                                                                                   |
| `(ds: 'foo', 'bar')`                                                                                                                | `{foo = true, bar = true}`                                                                                                                                                                                         |
| `(all-pass: _num where _num > 1 and < 14, 6, 8, 12, 10, 9)`                                                                         | <p><code>All({6, 8, 12, 10, 9}, function(it) it > 1 and num < 14 end)</code></p><p>🚧</p>                                                                                                                          |
| `(set: $foo to (macro: num-type _x, [(print: _x + 5)]))`                                                                            | `{$ function foo(x) show(x + 5) end $}`                                                                                                                                                                            |
| `(history:) contains "Cellar"`                                                                                                      | <p><code>Visited\["Cellar"]</code></p><p>🚧</p>                                                                                                                                                                    |
| `(metadata: "rarity", 5)`                                                                                                           | `{$ Passage.rarity = 5 $}`                                                                                                                                                                                         |
| `(passage: "Cellar")`                                                                                                               | `Passages["Cellar"]`                                                                                                                                                                                               |
| `(passages:)`                                                                                                                       | <p><code>Passages</code></p><p>Note that this is a map keyed by the passage name</p>                                                                                                                               |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://moontale.hmilne.cc/migration-guides/harlowe.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
