At some time when making your game you will need to use text. Text in games is dealt with by using the string functions (a string is just another way of saying a line of text) and GameMaker Studio 2 has a complete set of functions that permit you to manipulate strings in many ways, including the insertion of one string in another, the copying of strings and the ability to parse strings for the digits or the letters that they contain. In general a string can only be created by adding text within double quotes " " and single quote strings are not accepted, nor can you split the string over multiple lines and expect GameMaker Studio 2 to render it as if the line breaks were newlines (unless a string literal @ identifier is used, as explained below).

It is worth noting that there are certain conventions that you can use when creating strings, mostly concerned with using escape characters. These are characters that are preceded by a "\" symbol. So, for example, if you wanted to put quotation marks within a string you would have something like this:

str = "Hello\"World\"";

You can use the "\" to precede any Unicode literal - 4 digits of hex following a "u", for example "\u0000", where the 4 digits are the number of the Unicode character - or any hexadecimal literal - 2 digits of hex following a "0x", for example "\xff", where the 2 digits are the number of the character to use. These and other predefined escape characters are listed in the table below:

Constant Description
\n Newline
\r Carriage return
\b Backspace (0x08)
\f Form Feed (0x0c)
\t Horizontal Tab (0x09)
\v Vertical Tab (0x0b)
\\ Backslash itself (0x5c)
\a Alert (0x07)
\u[Hex Digits] Insert hex unicode character (note max 4 digits)
\x[Hex Digits] Insert hex unicode character
\[Octal Digits] Insert octal unicode character

NOTE: if you need characters right up against each other when using the octal or hex unicode values (ie. "\x1234567" and you only wanted the character 0x123 and the 4567 to be the actual digits) then end it with "\" and it will literally quote the next character (i.e. "\x123\4567")

NOTE: Strings support form feed, vertical tab etc... but this does not mean to say that rendering does, and when drawing strings these characters may be ignored.

You can also create verbatim string literals by preceding the whole string with the @ character:

var test = @"
Line breaks
over multiple

The above code will render the string over multiple lines as if there was a line break escape character included. A verbatim string literal is similar to previous GameMaker version string literals but they also use double or single quotes and must be prefixed by an @ symbol, they can be broken over multiple lines in the code file and they DO NOT support escaped characters i.e. @"Hello\World" will NOT try to escape the W on World and will be stored verbatim. Note though that when using string literals like this, you will need to break the string if you wish to include quotation marks as part of the string, ie:

var test = @"Hello " + "\"" + @"World" + "\""

Another thing to note is that the unicode character 9647 (▯) is used to substitute any missing glyphs that you may have in your designated font when rendering it in the draw event. So if your font doesn't have, for example, the ° symbol, then writing 90° will actually produce 90▯.

The following list of functions are all for dealing with strings:

Other than those functions that relate specifically to strings, the Windows target also permits you to use access the clipboard to get and set text information: