Escaping characters

From Adventure Game Studio | Wiki
Revision as of 12:50, 4 February 2014 by Monsieur'ouxx (talk | contribs) (Created page with " When you manage your AGS Strings, you might want to pay special attention to those two characters: * '''"''' (double quote) * '''\''' (backslash) * '''[''' (opening square br...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

When you manage your AGS Strings, you might want to pay special attention to those two characters:

  • " (double quote)
  • \ (backslash)
  • [ (opening square bracket, also known as left brace)

For easy solutions, simply read String_formatting#Displaying_special_characters. For thourough explanations, read below.


How to read this walkthrough There are 3 stages in managing your strings : 1) How you type them into the Editor 2) How they will actually be stored into the engine's memory, at runtime 3) How they will be rendered into the display: in a Label, in a Listbox, or in a Display command

In the AGS script editor :

(all the statements below tested in AGS 3.2.1)

Let's say you want to declare a string containing a backslash (\) and or a double quote ("), in the following fashion :

String s = "this is a string, and soon it will contain a backslash or a double quote";

In the script editor, the backslash acts as an escape character, which means it has no value in itself, but depends on what comes immediately behind.

  • One backslash followed by a double quote: \"

In editor:

String s = "aaa\"bbb";

In memory:

97 97 97 34 98 98 98

As you can see the backslash acts as an escape character and gets swallowed up so that the double quote doesn't get confused with the ending double quote.

By the way, this is not correct syntaxically, as there is no ending double quote:

String s = "aaa\";

At runtime, in a Label

  • If followed by a backslash \ : \\ allows you to store one "\" into memory at runtime, instead of having the backslash ignored (see below the sections about Labels, Listboxes, etc.)
  • Several backslashes followed by a brace [ : \\\\[ will only give you one [. All additional backslashes are ignored. Even the pairs of backslashes (\\) that you would expect to be turned into single \'s.
  • If followed by a double quote " : That's the only way for you to insert a double quote into a String by simply typing it (otherwise you might want to use AppendChar(eKeyBackslash)). The backslash will be ignored, and your double quote will be in the String, instead of causing an error at compiling time. The point about several backslashes preceding the double quote (explained earlier) also applies here.


WARNING: This page is still being redacted.