String
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 |
[edit] Usage
"The spy has spotted you! He's making a run for it!"
|
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.
"{!}Well done. Next we will cover attacking with weapons.\
|
Well done. Next we will cover attacking with weapons. For the purposes of this tutorial you have been equipped with bow and arrows, a sword and a shield. You can draw different weapons from your weapon slots by using the scroll wheel of your mouse. In the default configuration, scrolling up pulls out your next weapon, and scrolling down pulls out your shield. If you are already holding a shield, scrolling down will put your shield away instead. Try changing your wielded equipment with the scroll wheel now. When you are ready, go to the yellow flag to move on to your next task. |
—old Mount and Blade tutorial system, prior to Warband |
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.
[edit] 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.
("relation_plus_90_ns", "{s60} is devoted to you."),
|
—an example string tuple in Warband 1.134 |
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.
[edit] Formatting symbols
Strings can be formatted to a limited extent. Embedding a caret "^
" symbol into text will force a blank line to be produced.
"Lord Defects^^{s1} has renounced {reg4?her:his} allegiance to the {s3}, and joined the {s2}"
|
appears in game as |
---|
Lord Defects Lord Turya has renounced his allegiance to the Kingdom of Nords, and joined the Khergit Khanate |
[edit] 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.
[edit] Registers
- Main article: register
"Number of troops killed: {reg1}"
|
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.
[edit] String registers
- Main article: string register
"{s1} of {s3} has been taken prisoner by {s2}."
|
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.
[edit] Conditional strings
- Main article: conditional string
"But {reg4?she:he} is being held there as a prisoner in the dungeon of {s13}."
|
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.
[edit] Gender strings
- Main article: gender string
"Hello there, {laddie/lassie}. Have a drink on me.."
|
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.