Worlds are full of words: what a guard says, the questions a visitor may ask, a sign by the path, a shopkeeper's patter, a narrator. This page covers text as a value (strings, comparing, joining) and structured text: dialogue written as data that logic chooses from, made of lines, choices, and the act each choice performs.

Two principles run through it. Text is a value; saying it is an act. A speaker computes its words as a pure value, then performs say at a moment; it puts the words nowhere, and how they appear is decided elsewhere. And the description is kept until the last moment: text is rendered to pixels at the size it ends up on screen, so words on a sign stay sharp as you walk up.

Text values

How you write it. Text is written in double quotes, as Cone's string literals are (refterm.html, "Literals"). Cone's escapes apply: \n for a new line, π for a character by its number (refbasics.html).

"You have had your question."
"He would say: the door beside him."
let piLabel = "π";

One type. ConeScript has one text type, text. Cone has two, an owned String and a borrowed &str, and converts between them with String.from(...) (reftypecoll.html); the difference is about who owns the memory, which a world never says.

Comparing. Text compares with == and !=, byte for byte, and a match may test text against literals (refmatch.html, "Equivalence"):

match word {
  case "box" { 1 }
  case "ball" | "bat" { 2 }
  else { 0 }
}

Joining. Cone joins text with its append operator, <-, which takes several values at once (refbasics.html: print <- "π=", calcpi(10), "\n";). In ConeScript (illustration of the spelling):

var line = "Guard: ";
line <- answer(g, q);            // "Guard: The door beside me."

How numbers, moments and quantities with units are turned into text (a clock on the HUD, "12 m to go"), and whether text may hold placeholders filled in later, are open: neither Cone nor this design yet says.

Texts as data

A world declares the texts its logic chooses among, so the content says what may be said and asked, and the browser decides how to show it. The riddle's four questions are an enum, and their words a function over it (Values: enums); the guards' answers are texts returned by answer (Functions). Keeping answers as references to parts (eastDoor) until the last step, and turning them into words only at the end, keeps the logic checkable.

Saying: text as an act

What it is. say(speaker, text, to: being) is an act: the speaker (an NPC, a door, a radio, a player, a narrator) says these words to that being, now. It is performed in an acting block, never in a value block.

on(action(ask, q, to: g, by: v), {
  if within(v, g, 4 m) && !asked[v] {
    set(asked[v], true);
    say(g, answer(g, q), to: v);
  }
})

How it appears is the world's. The world has a rule that answers every speech act, on(spoke(speaker, text, to: v), ...), and manifests it as its designer chose: a bubble anchored above the speaker, a subtitle, text-to-speech, a chat-log line, several at once, or nothing out of earshot or through a wall. Only the act crosses the network; each visitor's machine manifests it, and the visitor's own preferences, such as captions or translation, may apply on top. See Overlays, HUDs and speech and Distribution.

Structured text: dialogue

What it is. Conversation written as data that logic chooses from: lines to be said, choices a visitor may pick, and the act each choice performs, for hundreds of lines chosen by many variables.

Why it is in the language. The ceiling on world logic is high for logic and low only for heavy computation (meshes, physics), which belongs in packages. Dialogue is logic, and a world must be able to write a lot of it: one shopkeeper's dialogue may serve forty shopkeepers.

How you might write it (illustration: the spelling is not chosen):

fn greeting(v: being) dialogue {
  dialogue([
    line(if lampLevel > 0 { "Evening. The lamps are lit." } else { "Good day." }),
    choice("What do you sell?",       then: offer(wares, to: v)),
    choice("Which way to the beach?", then: say(self, "Follow the lanterns.", to: v)),
    choice("Goodbye.")
  ])
}

What it means. Building a dialogue does nothing. It is presented by an act (which one is not yet spelled), each visitor's machine shows it as the world's style dictates (a panel with buttons, a list of spoken options), and a visitor's pick comes back as an action the world answers, as the riddle's questions do: the visitor chooses a named action carrying a value, aimed at a speaker, and the browser finds an input for it. The content says what may be chosen, never which key or button chooses it (Visitors and their actions).

Lines on a timetable are an animator whose values are lines of speech: keyframes of text (Animators).

Styled text

Text that carries styles (bold, italic, underline, size, color, links) within a run of words is a 2D matter. The richtext package holds documents of paragraphs, headings and lists whose text carries inline styles, with line breaking and layout. Fonts, sizes and wrapping on screen are on Layouts.

How it connects

Open questions

← Control flow | Contents | Parts →