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.
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.
A high-score table wants a name too:
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
- Add a Text object called Message in the Level tab.
- In Events, click + New event โ โ Special โ Always.
- Click the cell under Message and choose Set the text.
- Type
"Lives left: " + Str(Lives). Press Add and play.