Flag
A flag is an on-or-off state that can be attached to a given value through the use of the bitwise OR "|" masking operator. The name derives from the use of a semaphore signal: when the flag is raised, the state is active, while when the flag is lowered (not present), the state is inactive. In the case of binary, this "flag" translates instead to a single bit from a binary number: if the bit is 1, the state is active, whereas when the number is 0, the state is inactive. By assigning certain bits as flags, the remaining bits can be used for a number and the existence of the flag can be checked using a simple mathematical operation, allowing a single number to store several pieces of information without requiring something more complicated to develop.
In the Mount&Blade scripting language, all objects, functions, and variables are technically just numbers, so flags are added to object IDs and other similar constructs to store additional information about the objects. Flags are pre-defined by the Mount&Blade developers, as only the game engine itself is capable of performing decisions based on the presence or absence of flags in a given identifier.
How to use
The syntax of adding a flag is writing the name of the variable or object, the pipe key symbol "|
", and the name of the flag, for instance anyone|plyr
. The pipe key can be produced by pressing Shift+Backslash on a U.S. keyboard layout. More than one flag can be appended simply by adding additional pipes and flag names for the remaining flags. Each flag included will simply assign its corresponding bit inside the value.
The order of the flag and value does not matter — due to the mathematical operation used, a flag modified by a value is the same as a value modified by a flag.
Example
party_tpl|pt_looters|plyr
|
This example from module_dialogs.py associates the given dialogue with the pt_looters
party template, modified by the party_tpl
flag and the plyr
flag. As is evident, the order of the flags and the value doesn't matter, as long as they are appended to each other with the pipe symbol. The final resulting value in this case is for the Mount&Blade engine to allow the topic to appear when speaking to a group of looters (overriding the default assumption that pt_looters
is a troop, as in this case it is not), and the dialogue will be spoken by the player rather than the leader of the looter party.