A Sugar text is a possible message produced by an Item action or Boop. Every one starts with text. Boop texts live at the top level of its Code module. Item texts live inside the action that produces them.
Write an ordinary message
Put the message in quotation marks and finish it with a semicolon:
text "@1 pulls @2 closer.";
text tells Sugar that you are declaring a possible result. @1 and @2 become the participants’ names when the creation runs.
Put values inside a message
A pair of braces places a variable or property path directly inside Sugar text:
var keys = 5;
text "@1 found {keys} silver keys.";
This is interpolation. It is the normal way to include values in Sugar text, and the examples throughout this guide prefer it over repeated + concatenation.
Braces accept a variable name or property path such as {player.name}. A property path follows named information inside a value; the Lists, ranges, and objects lesson teaches the dot syntax in full. Interpolation does not calculate expressions, so calculate first when necessary:
text {
let keys = 2 + 3;
"@1 found {keys} silver keys."
}
Empty braces read following values in order:
text "@1 found {} keys and {} maps." with keys, maps;
Numbered braces start at 1 and can change that order:
text "The map shows {2}; the key opens {1}." with door, destination;
Use {{ for a literal { and }} for }. Sugar reports missing, unused, or invalid placeholders when the text runs or is tested in Sandbox Mode.
A variable and the text that uses it live together in Code. The following Values and types and Variables lessons explain every part of the declaration; for now, the complete module looks like this:
var mood = "playful";
text "@1 chose the {mood} challenge.";
Here mood means the current value of the variable declared directly above the text.
Add more than one possible text
Write another declaration on the next line:
text "@1 found a silver key.";
text "@1 found a secret note.";
text "@1 found an empty box.";
JOI chooses one matching text whenever the creation runs.
Leave yourself a note
Start a comment with //. Sugar ignores everything after it on that line:
// This text is shown when the creation runs
text "@1 found the golden ticket!";
Comments stay in your saved code and never appear in the result.
For now, every declaration on this page is one complete instruction ending in ;. Later lessons build up to text blocks that run several instructions and when conditions that decide which declarations are available.