Register

From Mount&Blade Modding Wiki
Revision as of 09:51, 24 June 2011 by JT (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Registers are the means of converting raw numbers into text that can be displayed to the player, by assigning a variable to the register and then "embedding" the register into a text string which is used in dialogue or messages. They are one of the four ways of producing dynamic text for the player (the others being string registers, conditional strings, and gender strings).

[edit] Using registers

Registers are used by inserting them ("embedding them") into a text string between braces ("{" and "}"). When the text is displayed to the player, the contents of the register are substituted in place of the braces. Variable names for registers are fixed and are defined by using the three letter code reg followed by a number starting from 0. For instance, the following text string:

Your liquid assets: {reg1}^Appraised value of stored goods: {reg2}

contains two registers, corresponding to register IDs 1 and 2, which will have to have values assigned prior to the string being shown to the player.

The assign function is used to set the value of registers.

[edit] Good practice

It is important to note that registers are not variables; they are intended to be used solely for the purpose of displaying numbers. They are assigned values from variables after they have been calculated and should not be directly manipulated. Think of a register as an "answer" that has been written down on the page after the calculations have been performed. It is far more ideal to use local variables and global variables with proper names as needed for calculations, then to assign them to registers after the calculations are complete.

While registers can and do work with store_add, val_add, etc., this should be avoided if possible as using variables makes what you are doing much clearer to the person reading your source code.

The only function that is intended to work with registers directly is shuffle_range.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox