Skip to content

Commit 6c16c3c

Browse files
authored
Add documentation for comparison operators in variable shorthand syntax (#185)
- Document new comparison operators for variable shorthands - Add section explaining macro autocomplete
1 parent d22fbb6 commit 6c16c3c

1 file changed

Lines changed: 93 additions & 5 deletions

File tree

Usage/macros.md

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,23 @@ Macros are dynamic placeholders that get replaced with actual values when text i
1818
SillyTavern provides built-in documentation for all available macros:
1919

2020
- **Slash command**: Type `/? macros` in the chat input to display a list of all registered macros with their descriptions.
21-
- **Autocomplete**: Type `{{` during slash commands autocomplete in the input field to get suggestions for available macros.
21+
- **Autocomplete**: See [Macro Autocomplete](#macro-autocomplete) below for details on getting suggestions while typing.
22+
23+
### Macro Autocomplete
24+
25+
Macro autocomplete provides suggestions for available macros as you type. It works in all text fields that support macros throughout SillyTavern.
26+
27+
Type `{{` to start autocomplete for macros, showing available macros and their arguments, potential [Macro Flags](#macro-flags), [Variable Shorthands](#variable-shorthands), and more.
28+
29+
**Where autocomplete appears by default:**
30+
31+
- Expanded editor (full-screen text editing, opened via the 'Expand' button next to text fields)
32+
- Prompt manager editor
33+
34+
**Triggering autocomplete in other fields:**
35+
36+
- Press **Ctrl+Space** in any macro-supporting text field to open the autocomplete popup
37+
- Enable **Settings → AutoComplete Settings → Show in all macro fields** to have autocomplete appear automatically in all macro fields
2238

2339
## Basic Syntax
2440

@@ -217,7 +233,7 @@ The condition can be:
217233

218234
- A macro name (resolved automatically if no arguments are required)
219235
- Any value from a nested macro like `{{getvar::flag}}`
220-
- A variable shorthand like `.myFlag` or `$globalFlag` (see [Variable Shorthand Syntax](#variable-shorthand-syntax))
236+
- A variable shorthand like `.myFlag` or `$globalFlag` (see [Variable Shorthands](#variable-shorthands))
221237
- Any text you want (that will implicitly resolve to truthy or falsy based on its content)
222238

223239
Falsy values: empty string, `false`, `0`, `off`, `no`.
@@ -236,7 +252,7 @@ Variable shorthands provide a concise way to check variable values in conditions
236252
{{ /if }}
237253
```
238254

239-
See [Variable Shorthand Syntax](#variable-shorthand-syntax) for more details on shorthand notation.
255+
See [Variable Shorthands](#variable-shorthands) for more details on shorthand notation.
240256

241257
### Inverted Condition
242258

@@ -318,7 +334,7 @@ Whitespace is allowed between flags and the macro name:
318334
### Flags-like prefix operators
319335

320336
Variable shorthand syntax uses prefix operators (`.` and `$`) which behave similarly to flags but are not flags themselves.
321-
See the [Variable Shorthand Syntax](#variable-shorthand-syntax) section for details.
337+
See the [Variable Shorthands](#variable-shorthands) section for details.
322338

323339
### Preserve Whitespace Flag
324340

@@ -361,7 +377,7 @@ To display literal curly braces without macro resolution, escape them with backs
361377

362378
This outputs `{{notAMacro}}` as plain text.
363379

364-
## Variable Shorthand Syntax
380+
## Variable Shorthands
365381

366382
!!!warning Staging Feature
367383
This is currently only available on the `staging` branch of SillyTavern, and not part of the latest release.
@@ -427,6 +443,10 @@ The following operators can be used with variable shorthands. Each operator foll
427443
| `??=` | [Nullish Coalescing Assign](#nullish-coalescing-assign) | `{{.name ??= Guest}}` | Sets value only if variable is undefined, returns the new value |
428444
| `==` | [Equals](#equals) | `{{.status == active}}`| Compares values, returns `"true"` or `"false"` |
429445
| `!=` | [Not Equals](#not-equals) | `{{.status != active}}`| Compares values, returns `"true"` if not equal |
446+
| `>` | [Greater Than](#greater-than) | `{{.score > 50}}` | Returns `"true"` if variable is greater than value |
447+
| `>=` | [Greater Than or Equal](#greater-than-or-equal) | `{{.level >= 10}}` | Returns `"true"` if variable is greater than or equal to value |
448+
| `<` | [Less Than](#less-than) | `{{.health < 20}}` | Returns `"true"` if variable is less than value |
449+
| `<=` | [Less Than or Equal](#less-than-or-equal) | `{{.health <= 0}}` | Returns `"true"` if variable is less than or equal to value |
430450

431451
#### Get Variable
432452

@@ -582,6 +602,74 @@ Useful in `{{if}}` conditions:
582602
{{if {{.status != disabled}} }}Feature enabled{{/if}}
583603
```
584604

605+
#### Greater Than
606+
607+
Use `>` to check if a variable's numeric value is greater than another value:
608+
609+
```txt
610+
{{.score > 50}} // Returns "true" if .score is greater than 50
611+
{{$level > 5}} // Returns "true" if $level is greater than 5
612+
```
613+
614+
Performs a numeric comparison and returns the literal string `"true"` or `"false"`.
615+
616+
Useful in `{{if}}` conditions:
617+
618+
```txt
619+
{{if {{.score > 100}} }}High score!{{/if}}
620+
```
621+
622+
#### Greater Than or Equal
623+
624+
Use `>=` to check if a variable's numeric value is greater than or equal to another value:
625+
626+
```txt
627+
{{.level >= 10}} // Returns "true" if .level is at least 10
628+
{{$points >= 100}} // Returns "true" if $points is 100 or more
629+
```
630+
631+
Performs a numeric comparison and returns the literal string `"true"` or `"false"`.
632+
633+
Useful in `{{if}}` conditions:
634+
635+
```txt
636+
{{if {{$level >= 10}} }}Unlocked advanced features{{/if}}
637+
```
638+
639+
#### Less Than
640+
641+
Use `<` to check if a variable's numeric value is less than another value:
642+
643+
```txt
644+
{{.health < 20}} // Returns "true" if .health is below 20
645+
{{$timer < 0}} // Returns "true" if $timer is negative
646+
```
647+
648+
Performs a numeric comparison and returns the literal string `"true"` or `"false"`.
649+
650+
Useful in `{{if}}` conditions:
651+
652+
```txt
653+
{{if {{.health < 20}} }}Low health warning!{{/if}}
654+
```
655+
656+
#### Less Than or Equal
657+
658+
Use `<=` to check if a variable's numeric value is less than or equal to another value:
659+
660+
```txt
661+
{{.health <= 0}} // Returns "true" if .health is 0 or below
662+
{{$attempts <= 3}} // Returns "true" if $attempts is 3 or fewer
663+
```
664+
665+
Performs a numeric comparison and returns the literal string `"true"` or `"false"`.
666+
667+
Useful in `{{if}}` conditions:
668+
669+
```txt
670+
{{if {{.health <= 0}} }}Game over{{/if}}
671+
```
672+
585673
## Legacy Syntax
586674

587675
For backwards compatibility, angle bracket markers are still supported:

0 commit comments

Comments
 (0)