Strings

A **string** is a sequence of printable symbols (letters, numbers, spaces, punctuation, and special characters) surrounded by quotation marks, ultimately used to be displayed to the player in one fashion or another. All text in the game consists of strings, whether dialogue in module\_dialogs.py, script messages in module\_scripts.py, troop names in module\_troops.py, info pages in module\_infopages.py, etc.

Contents
[hide]
* 1 Usage
* 2 module\_strings
* 3 Formatting symbols
* 4 Dynamic text
	+ 4.1 Registers
	+ 4.2 String registers
	+ 4.3 Conditional strings
	+ 4.4 Gender strings

## Usage

A string must appear on a single line within the module system code, although the line continuation feature of Python (the backslash "`**\**`" symbol) can be used to break up a very long line inside the code. The line breaks made in this fashion will not translate over into the real game, which will still wrap the text intelligently as needed.

In some cases, especially in game menus and dialogs, Mount&Blade also intelligently scales down text to fit the space available. If you attempt to use a very long string as a dialogue choice, for instance, it will be shrunk down to fit the size of the button on screen. If you attempt to use a very long string as text spoken by an NPC, it will be shrunk to a certain extent. Note that there are limits to this shrinkage and it is entirely possible to present a string that is simply too big to fit.

## module\_strings

Strings used for functions are defined primarily in the file module\_strings.py in the module system. This simple but large file consists of tuples, each containing a string ID followed by an actual string. When a function expecting a string ID is used, it is provided the ID from the module\_strings.py file and the string corresponding to that ID is used as the text to display or manipulate.

Quick strings can also be used instead of a string from module\_strings in place of a string ID. Instead of specifying a string ID, a quick string consists of the actual text to use, but prefaced with a strudel "`**@**`" symbol. However, quick strings can be inconvenient to manage.

## Formatting symbols

Strings can be formatted to a limited extent. Embedding a caret "`**^**`" symbol into text will force a blank line to be produced.

## Dynamic text

A basic string is presented exactly as written to the player, called "static text". Static text is assigned to such things as troop names and item names. Once defined in the module system, the name is permanent and cannot generally be changed by script while the game is in progress.

In some circumstances, such as quest, dialogue, and messages, it is also possible to produce "dynamic text" — text that changes — by using specially-constructed strings that make use of registers, string registers, conditional strings, and gender strings. By running script code prior to displaying this text, the registers can be "loaded" with information that will then be displayed when accessed by the player. Or, of course, simple static text can be used if it is not necessary.

### Registers

* *Main article: register*

Registers contain numeric data to be displayed to the player. They are assigned either directly from various scripts or functions, or specifically assigned a value by the mod designer immediately before being displayed. In all current versions of Mount&Blade, registers (and all other variables, actually) can only contain *integers*, which is to say that they only contain whole numbers with no decimal, not *floating point* numbers.

Registers are very similar in purpose to global variables, but are chiefly used for output rather than for calculations. Registers are re-used as necessary from circumstance to circumstance and they should always be considered to be "volatile" — *i.e.*, from one moment to the next, something else may have changed the value, so you should never use a register unless you have immediately assigned a value to it or you know that something else has immediately assigned a value to it.

### String registers

* *Main article: string register*

String registers are exactly like registers but are used to store text for display to the player. They are replaced with text which has been explicitly assigned to them in advance.

### Conditional strings

* *Main article: conditional string*

Conditional strings check the current value of a register and then, depending on whether the register contains a non-zero ("true") value, are replaced by one item or another.

### Gender strings

* *Main article: gender string*

Gender strings are replaced by either a male oriented string or a female oriented string depending on who the person listening to the conversation is. This of course only works in dialogue.

## Conditional string

A **conditional string** is an embedded expression in a string that evaluates to one of two possibilities based on the value contained in a given register. If the register contains a non-zero value, the first choice is used; otherwise the second choice is used. Either choice can be blank. Persons familiar with programming will recognise a conditional string as the ternary operator "`**?:**`".

### Using conditional strings

Conditional strings are formatted by using the name of a register, followed by a question mark "`**?**`" and the string to use if true, followed by a colon "`**:**`" and the string to use as false, all surrounded by braces "{" and "}".

A common example of a conditional string is below:

```
town{reg0?s:}

```

If *reg0* is not equal to 0, the embedded expression will yield "s", otherwise it will yield "" (a blank string). Thus, the final resulting string will be

```
towns

```

if *reg0* is not equal to 0, or

```
town

```

if *reg0* is equal to 0. This is the principal method of pluralisation in Mount and Blade dialogue and scripting.

### Complex conditional strings

Conditional strings can be embedded within each other in any combination desired. For instance,

```
{reg6?I:{reg7?You:{s11}}}

```

will display "I" if register 6 is true, "You" if register 7 is true, or the contents of string register 11 (in this case containing the name of a lord) if neither are true. This is a compact and elegant method that is more space efficient than using a string register directly and then assigning "I", "You", or the name of a person to that register as needed.

As a matter of style, if a conditional string is embedded more than twice, it is generally better to separate that logic out and assign a string register using a **try\_begin**/**else\_try**/**try\_end** block.