From NWN Lexicon
Revision as of 13:26, 29 May 2020 by Jasperre (talk | contribs) (+some notes on limits)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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.


string sHero = "Galryx";
string sConcat = "Hello" + " there!"; // "Hello there!"
string sName = GetName(GetFirstPC()); // Gets the name of the first PC and stores it in sName

Escaped Characters

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.

Warning icon orange.png Caution: This section documents changes arising in NWN: Enhanced Edition content. The content is available in both the classic version and the Enhanced Edition of the game. However, the behavior may vary in each version. More details may be available in the [1] NWN Enhanced Edition patch notes.

As of NWN:EE version 74.8168, strings may now contain double-quote characters if the double-quote is escaped using a backslash. For example:

void main()
    // The NPC says: So I respond, "That's what she said!"
    SpeakString("So I respond, \"That's what she said!\"");

See Also


String Functions


EFFECT_TYPE_* Constants