A sequence of characters of arbitrary length. The default value is an empty string (""). Strings can be concatenated (that is, combined) by using the plus ("+") sign. A string can be compared for equality against another string by using the double equals ("==") equality tester, or for inequality by using the "!=" equality tester. When testing for string equality, strings are case-sensitive (that is "SoME CHaRaCTeR NaMe" does not equal "some character name").
Note a single defined string can have up to 511 characters before the compiler stops working. To get around this limitation you can use concatenated strings or pull the strings from other sources outside the script (anything that returns a string value won't have this limit imposed).
To make static strings in larger scripts more efficient at runtime consider using the const keyword. Strings tend to be the worst performance-wise for large loops and complicated manipulations.
There are a number of String Functions that can help manipulate, test, and alter strings.
Some characters may be preceded by a backslash (\) to generate special characters. This is called escaping the character. For example, \t results in a tab character and \n results in a newline character.
As of NWN:EE version 1.74.8168, strings may now contain double-quote characters if the double-quote is escaped using a backslash (\"). For example:
This can be used to generate more colour tokens then you'd usually be able to using nwscript, since the compiler would not like some of the extended range of ASCII. Of course the non-printable characters do not show up if used in a string you print to view.
This function can now show almost any colour text, except entirely black since \x00 is not available.
// This requires a later version of NWN:EE to use the \x escape character
// For more information: https://nwn.wiki/display/NWN1/Colour+Tokens
// NB: First character is "nearest to 00" since we can't use \x00 itself (means you can't get completely black is all)
// Gets a suitable <cXXX> token to use at the start of a block of colored text. Must be terminated by </c>
// - nRed - Red amount (0-255)
// - nGreen - Green amount (0-255)
// - nBlue - Blue amount (0-255)
string GetColorCode(int nRed=255, int nGreen=255, int nBlue=255)
return "<c" + GetSubString(COLOR_TOKEN, nRed, 1) + GetSubString(COLOR_TOKEN, nGreen, 1) + GetSubString(COLOR_TOKEN, nBlue, 1) + ">";
SpeakString(GetColorCode(255, 20, 147) + "Speaking in Deep Pink!" + "</c>");