# Sugarcube

Examples taken from the [Sugarcube online documentation](http://www.motoslave.net/sugarcube/2/docs)

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

## Macros and Functions

As a rule, Moontale makes no distinction between a 'macro' and a 'function'. The changer syntax `$foo[Text]` makes use of `foo` as a Lua function, and using it in code e.g. `{$ x = foo(y) $}` is just as valid.

## Syntax

The following syntax is identical in Sugarcube and Moontale:

* `[[Passage]]`
* `[[Link -> Target]]`
* `[[Target <- Link]]`
* `$variable`
* `* Unordered lists`
* `> Blockquote`

| Sugarcube                                                                                                                                                                                           | Moontale                                                                                                                                                    |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<<print $name>>`                                                                                                                                                                                   | `{$ Show(name) $}`                                                                                                                                          |
| `<<= 2 + 3>>`                                                                                                                                                                                       | `<$ 2 + 3 $>`                                                                                                                                               |
| `"""No markup"""`                                                                                                                                                                                   | `<$ 'No markup' $>`                                                                                                                                         |
| `{{{$name}}}`                                                                                                                                                                                       | `` `$name` ``                                                                                                                                               |
| `[[Label\|Target]]` and `[[Label][Target]]`                                                                                                                                                         | `[[Label->Target]]`                                                                                                                                         |
| `[[Go buy milk\|Grocery][$bought to "milk"]]`                                                                                                                                                       | `$On.click<<bought = 'milk'; Jump('Grocery') end>>[Go buy milk]`                                                                                            |
| `[img[Image][Link]]` etc.                                                                                                                                                                           | `[[$Image('path/to/image')->Target]]`🚧                                                                                                                     |
| <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>Note the extra space to force a line break</p>    |
| `!Heading 1`                                                                                                                                                                                        | `# Heading 1`                                                                                                                                               |
| `!!Heading 2`                                                                                                                                                                                       | `## Heading 2`                                                                                                                                              |
| `//Emphasis//`                                                                                                                                                                                      | `*Emphasis*` or `_Emphasis_`                                                                                                                                |
| `''Strong''`                                                                                                                                                                                        | `**Strong**` or `__Strong__`                                                                                                                                |
| `==Strikethrough==`                                                                                                                                                                                 | `~~Strikethrough~~`                                                                                                                                         |
| `__Underline__`                                                                                                                                                                                     | `$Style.u[Underline]`                                                                                                                                       |
| <p><code># Item 1</code></p><p><code># Item 2</code></p>                                                                                                                                            | <p><code>1. Item 1</code></p><p><code>1. Item 2</code></p>                                                                                                  |
| `{{{Code}}}`                                                                                                                                                                                        | `` `Code` ``                                                                                                                                                |
| <p><code>{{{</code><br><code>Code</code><br><code>}}}</code> </p>                                                                                                                                   | <p><code>`</code><br><code>Code</code><br><code>`</code></p>                                                                                                |
| `----`                                                                                                                                                                                              | `---` or `***`                                                                                                                                              |
| Templates, e.g. `?He was always willing to lend ?his ear to anyone.`                                                                                                                                | <p><code>$Name.myTemplate\[$He was always willing to lend $his ear to anyone.]</code></p><p><code>$With{He = 'She', his = 'her'}\[$myTemplate]</code>🚧</p> |
| <p><code>/\* Comment \*/</code></p><p><code>/% Comment %/</code></p><p><code>\<!-- Comment --></code></p>                                                                                           | `{$--[[ Comment --]]$}`                                                                                                                                     |
| `<<capture foo bar>>`                                                                                                                                                                               | `{$ local foo = foo; local bar = bar $}`                                                                                                                    |
| `<<run foo()>>` and `<<script>>foo()<</script>>`                                                                                                                                                    | <p><code>{$ foo() $}</code></p><p>(Of course, this is Lua rather than JavaScript)</p>                                                                       |
| `<<set $gold to 5>>`                                                                                                                                                                                | `{$ gold = 5 $}`                                                                                                                                            |
| `<<unset $cheese, $gold>>`                                                                                                                                                                          | `{$ cheese = nil; gold = nil $}`                                                                                                                            |
| `<<include "Go West">>`                                                                                                                                                                             | `[[ ->Go West]]`                                                                                                                                            |
| `<< if $cash lt 5>>`                                                                                                                                                                                | `$If(cash < 5)[`                                                                                                                                            |
| `<<for i, name range $dwarves>>`                                                                                                                                                                    | `$ForEach(dwarves)[`                                                                                                                                        |
| `<<break>>` and `<<continue>`                                                                                                                                                                       | Not supported in markup - use a script block with a `for` loop                                                                                              |
| <p><code><\<switch $hairColor>></code></p><p><code><\<case "black" "brown">></code></p><p>        <code>Dark haired, eh?</code></p><p><code><\<default>></code></p><p><code><\</switch>></code></p> | <p><code>$Switch(hairColor)</code> <br><code>$Case('black', 'brown')\[ Dark haired, eh? ]</code></p><p><code>$Else\[  ]</code>🚧</p>                        |
