Text formulas

Join words and numbers with Str, read what the player typed, and cut text up with Left, Right and Mid.

Words in a formula

Text goes in double quotes: "Hello!". Join pieces with +: "Score: " + "100" is "Score: 100". Joining a number to words turns it into text as well, so "Score: " + Score works. Str does the same on purpose, and is the way to make a number into text when there are no words to join it to.

The place to use text formulas is Set the text on a Text object, and Add the score to the table, which asks for a name.

WhenAlways
DoSet text of Message to "Score: " + Str(Score)

The text functions

Str(42)Turns a number into text, โ€œ42โ€. Use it before joining a number to words.
Val("42")Turns text into the number 42. Use it to do sums with what the player typed.
Len("hello")The number of letters, 5.
Left("hello", 2)The first letters, โ€œheโ€.
Right("hello", 2)The last letters, โ€œloโ€.
Mid("hello", 1, 3)Three letters starting after the first one, โ€œellโ€. Counting starts at 0.
Text("Message")The words a Text object, Button or Text box is showing.

What the player typed

A Text box object lets the player type. Text("Name box") is what they wrote. The condition The player presses Enter fires when they press Enter.

WhenThe player finishes typing in Name box (presses Enter)
DoSet text of Greeting to "Hello, " + Text("Name box") + "!"Empty Name box

A high-score table wants a name too:

WhenNumber of lives is = 0The score is good enough for Table
DoAdd the score to Table as Text("Name box")

Doing sums with typed text

Typed text is text even when it looks like a number. Wrap it in Val first: Val(Text("Answer box")) * 2. In a quiz, compare Val(Text("Answer box")) with the right answer using Compare two values.

How to

  1. Add a Text object called Message in the Level tab.
  2. In Events, click + New event โ†’ โš™ Special โ†’ Always.
  3. Click the cell under Message and choose Set the text.
  4. Type "Lives left: " + Str(Lives). Press Add and play.

Still stuck?

Try the Chocobreak tutorial, open a sample game and read its rules, or look at the questions people ask.