Message strings#
Message strings are defined in the string editor: Quests > Strings. The text content of a message string is a mix of literals (ex: “It’s dangerous to go alone!”) and string control codes, which are abbreviated as SCC (ex: for changing the text color, or warping the player, etc). SCCs can be typed manually in the string editor, or inserted via the SCC wizard.
When a message string is rendered, the literals and commands print and execute in order.
This page describes the syntax for message strings, lists all SCCs, and describes how to work with message strings in ZScript.
Syntax#
The syntax for a SCC is this: \CommandName\arg1\arg2\, where “arg1” and “arg2” are numbers.
Unless the SCC is at the end of a string, the last slash must be followed by a space (the space will be ignored by the string parser)
The command name is case insensitive
Instead of the command name, the code can be used too. But when saved the editor will change it to the command name
Certain characters must be escaped with a backward slash:
\\,\{,\}
For example: It's dangerous to go alone! \TextColor\2\3\ Take this! first prints “It’s dangerous to go alone! “, changes the text color, then prints “Take this!”. There will be exactly one space between the sentences (“It’s dangerous to go alone! Take this!”), but there would be no spaces if the message string were instead It's dangerous to go alone!\TextColor\2\3\ Take this!.
If the author makes an error when writing a SCC, the command will not execute and instead will display as a string literal.
A valid command requires:
A specific number of arguments
Each argument to be valid
A slash at the end of each command (including a space, except if the command is at the end of string)
Note
{ and } are reserved for future enhancements, which is why they must be escaped.
Syntax (2.55)#
2.55 has a slightly different syntax for SCCs in the string editor:
Commands use codes, not names:
\1\arg1\arg2Commands do not end with a
\and a spaceCommands arguments cannot be negative
ASCII characters can be inserted using the “commands”
\31 through \125. The ASCII value printed is 1 more than the number in the string.To print a backwards slash, the only option is
\91The syntax expects authors to make no mistakes when typing out SCCs. For example, if you provide 3 arguments instead of 2, the last argument will be interpreted as the next command, potentially resulting in strange effects
However, in 2.55 the string as shown in the editor is not how the string is encoded; it uses a special binary encoding, not ASCII. Scripts that access string data via messagedata must be familiar with this binary encoding. See the “ZScript” section for more.
Commands#
Formatting#
These commands affect how the string is rendered, such as changing the font, text color, or inserting characters or tiles into the message.
Code |
Format |
Format (2.55) |
Description |
|---|---|---|---|
1 |
|
|
Changes the text color to the specified color |
26 |
|
|
Changes the shadow color to the specified color |
27 |
|
|
Changes the shadow type to the specified style. See “Shadow types” below table |
2 |
|
|
Changes the text speed. ‘speed’ is the number of frames between each character, where ‘0’ is instantaneous |
155 |
|
not supported |
Delays string processing by number of frames. Respects A/B button speed up (if appropriate QRs enabled). |
156 |
|
not supported |
Delays string processing by number of frames. Does not respect A/B button speed up |
135 |
|
|
Changes the text font. ‘font’ is the ID number of the new font to use |
25 |
|
|
New Line - breaks to the next line |
22 |
|
|
Inserts the save file name as text |
151 |
|
not supported |
Inserts the value of the given counter as text |
152 |
|
not supported |
Inserts the max value of the given counter as text |
28 |
|
|
Draws a tile block inline with the text, as though it were a custom font character |
24 |
|
|
Unimplemented; reserved for changing portrait |
Shadow types:
No Shadow
Basic shadow, no text
‘U’ shadow, no text
Full outline shadow, no text
‘+’ outline shadow, no text
‘X’ outline shadow, no text
Basic shadow, behind text
‘U’ shadow, behind text
Full outline shadow, behind text
‘+’ outline shadow, behind text
‘X’ outline shadow, behind text
Switch#
These commands conditionally change to a different string. If switched to a string that does not exist, an empty string will be loaded.
Code |
Format |
Format (2.55) |
Description |
|---|---|---|---|
3 |
|
|
if |
23 |
|
|
Same as above, but for any screen (not just the current) |
4 |
|
|
Randomly has a 1/factor chance to switch to newstring |
5 |
|
|
Go to newstring if the specified item is owned |
6 |
|
|
Go to newstring if the specified counter is >= value |
7 |
|
|
Go to newstring if the specified counter is at least percent full |
8 |
|
|
Go to newstring if the triforce from the specified level is owned |
9 |
|
|
Go to newstring if at least numtriforce triforce pieces are owned |
131 |
|
|
Go to newstring if menu selection. Switches to the new string if ‘pos’ is the selected menu position |
138 |
|
not supported |
Go to newstring if global state is specified value. Valid “state” is 0-255. “value” of 0 checks for disabled, 1 checks for enabled. |
139 |
|
not supported |
Go to newstring if current screen state is of specified value. For values of “state”, see ScreenState. |
140 |
|
not supported |
Same as above, but for any map/screen. |
141 |
|
not supported |
|
142 |
|
not supported |
|
143 |
|
not supported |
Go to newstring if level state is specified value. -1 for “level” means current level. Valid “state” is 0-31. “value” of 0 for false, non-zero for true. |
144 |
|
not supported |
Go to newstring if level item is specified value. -1 for “level” means current level. Valid “item” is 0-15 (see order of LevelItemBitflags). “value” of 0 for false, non-zero for true |
145 |
|
not supported |
Go to newstring if current screen secrets have triggered. |
Control Mod#
These commands modify counters or items.
Code |
Format |
Format (2.55) |
Description |
|---|---|---|---|
10 |
|
|
Adds ‘val’ to ‘ctr’ |
11 |
|
|
Subtracts ‘val’ from ‘ctr’ |
12 |
|
|
Sets ‘ctr’ to ‘val’ |
13 |
|
|
Adds ‘percent’ % to ‘ctr’ |
14 |
|
|
Subtracts ‘percent’ % from ‘ctr’ |
15 |
|
|
Sets ‘ctr’ to ‘percent’ % full |
16 |
|
|
Gives the player ‘itemid’, silently. The item is not held up, nor does its’ pickup script run; though its’ counter effects will |
154 |
|
not supported |
Same as above, but not silent. The item will be collected and held up when the message box closes (after any linked messages). |
17 |
|
|
Takes ‘itemid’ from the player, silently. Its’ pickup counter modifications will be reversed when removed |
Misc#
Code |
Format |
Format (2.55) |
Description |
|---|---|---|---|
18
|
\Warp\dmap\screen\x\y\effect\sound\ |
\18\dmap\screen\x\y\effect\sound |
Warps the player to ‘dmap,screen’
If x < 0, then y is treated as a return square(0-3 for return squares A-D, 5 for pit warp).
If x >= 0, then x and y act as destination coordinates.
Effects:
0. WARPEFFECT_NONE
1. WARPEFFECT_ZAP
2. WARPEFFECT_WAVE
3. WARPEFFECT_INSTANT
4. WARPEFFECT_OPENWIPE
|
19 |
|
|
Sets |
20 |
|
|
Plays a specified sfx |
21 |
|
|
Plays a specified quest midi (cannot play the built-in midis) |
29 |
|
|
Immediately exits the current string. If there is a ‘next string’, it will begin immediately. The prompt to press ‘A’ to continue will be skipped |
30 |
|
|
Pauses the string and prompts the player to press A to continue (as normally occurs at the end of a string) |
132 |
|
|
Triggers secrets, which are permanent unless ‘perm’ is ‘0’ |
133 |
|
|
Sets a screen state on the current screen. For values of “state”, see ScreenState. |
134 |
|
|
Same as above, but for any map/screen |
146 |
|
not supported |
|
147 |
|
not supported |
|
148 |
|
not supported |
Sets the global specified state. Values of -1 means “enabled”, 0 means “disabled”, and “>0” means “enabled for x frames” |
149 |
|
not supported |
Sets the level state. -1 for “level” means current level. Valid “state” is 0-31. “value” of 0 for false, non-zero for true. |
150 |
|
not supported |
Sets the level item. -1 for “level” means current level. Valid “item” is 0-15 (see order of LevelItemBitflags). “value” of 0 for false, non-zero for true. |
136 |
|
|
Run the specified generic script, in RunFrozen mode |
137 |
|
|
|
153 |
|
not supported |
Kills the player instantly (plays the death animation). If bypass_revive is zero, fairies may prevent death. |
ZScript#
Scripts can read or write to message strings via messagedata, which includes SCCs.
Added in version 3.0: The individual string literals and commands can be read via messagedata::Segments[].
In 2.55, the text stored in messagedata uses a binary encoding: how the string is displayed in the editor is not how it appears in scripts; each command is not stored as \1\2\3, but instead the command code and each argument is encoded as that value plus 1. For example, \1\2\3 encodes as three numbers: 2, 3, 4.
Since 3.0, the text stored in messagedata is exactly the text seen in the editor: it’s just ASCII. However, the older binary encoding can still be used if qr_OLD_SCRIPTS_MESSAGE_DATA_BINARY_ENCODING is enabled. This is only necessary if the strings contain SCCs, and if the code processing them still expect the binary encoding.
Example: Writing SCCs#
The following are a couple example scripts found in ZC’s tests folder, which gives some insight into how to programmatically write SSCs.
The first test script shows examples for writing in both the ASCII and binary encodings:
The second test script shows just writing SCCs in the binary encoding:
Example: Reading SCCs#
For reading SCCs, it’s highly recommended to use messagedata::Segments[], which handles the parsing and works the same regardless of the encoding used.
This example is from tango, the text library. It shows reading SCCs from the binary encoding.