String formatting

From Adventure Game Studio | Wiki
Jump to navigation Jump to search
  • Inserting strings: %s
Display("Your name is %s.", player.Name);
  • Inserting letters: %c
Display("%c is a letter.", mychar);

or

Display("The first letter of the alphabet is the %c", 'A');
  • Inserting floats: %f
Display("%f is a floating point number.", myfloat);
  • Inserting integers: %d
Display("%d is a number.", myint);

Integer format flags

  • Creating field (number) characters wide: %(number)d
Display("Here comes %4d a test", 22); //=> Here comes   22 a test
  • Left justify: -
Display("Here comes %-4d a test", 22); //=> Here comes 22   a test
  • Padding field with 0's instead of blanks: 0
Display("Here comes %04d a test", 22); //=> Here comes 0022 a test
  • Sign of number always shown: +
Display("Here comes %+d a test", 22); //=> Here comes +22 a test
  • Positive values begin with a blank: (blank)
Display("Here comes % d a test", 22); //=> Here comes  22 a test

Displaying special characters

  • Character to mask % symbol in strings: %
Display("The %% is the percent symbol.");
  • Character to mask quotemarks in strings: \
Display("The \" is a quotemark.");
  • Character for line breaks in strings: [
Display("The [ is a line break.");
  • Character to mask [ in strings: \
Display("The \[ is a left brace.");

More about "escaping" characters: nasty tricks are detailed here.