# Variable strings in localization

The game settings provide the ability to configure the order button and assign hotkeys for in-game actions. This requires identifying the corresponding keys in the localization files. \
For this, variable strings are used.

## Types of Variable Strings

### **Giving orders in the Game**

`<&mouse_action_key>`

{% hint style="info" %}
By default, right-click button orders are used. \
In the Options window, players can enable left-click button orders by selecting the "LMB orders" checkbox.
{% endhint %}

<figure><img src="/files/bkd7MDZKF5oTEGl6CGfz" alt=""><figcaption><p>Switching Order button from Right-Click to Left-Click in the OPTIONS window</p></figcaption></figure>

### **Specifying an in-game action**

`<&optkey:anyAction>`

When displaying localization texts, the value corresponding to the user's settings recorded in the `keys.opt` file will be substituted instead of `<&optkey:anyAction>`.

<details>

<summary><strong>Example of specifying hotkeys for actions in localization texts</strong></summary>

Assume the "cancel" action is assigned to the Z key. Then the `keys.opt` file will have the following lines:

```
{"actions/cancel"
    {value KEY_Z}
}
```

For the `actions/cancel` action, the localization lines might look like this:

```
{"stand_still" "To cancel an order, press the hotkey <&optkey:actions/cancel>."}
```

In the game text, the letter Z will be displayed instead of the variable string `<&optkey:actions/cancel>`, and the player will see:

**"To cancel an order, press the hotkey Z."**

*Note: To ensure the action is found by the hotkey, the key parameter must be specified for the action in the `action.set`file:*

```
{...{name "[action_name]"} ...{key "actions/[action_name]"}...}
```

If you need to add the ability to trigger an action by hotkey, you can create the `action+.set` file and use the block with the modify parameter. For example, for the "cancel" action:

```
{modify "cancel"...{key "actions/cancel"}...}
```

</details>

### **Specifying a keyboard key**

`<&key:keycode>`

Used to specify a specific keyboard key.&#x20;

<details>

<summary><strong>Example of specifying a specific key in localization texts</strong></summary>

For the spacebar key, the variable string in localization files will look like this:

```json
{"continue" "Press <&key:key_space> key to continue"}
```

</details>

To specify keys, you need to use values from the `keycode` list.

<details>

<summary>List of keycode values for keyboard keys</summary>

Note: For better readability, it is recommended to write in lowercase.\
keymap\["KEY\_ESCAPE"] = 0x01;

keymap\["KEY\_1"] = 0x02;

keymap\["KEY\_2"] = 0x03;

keymap\["KEY\_3"] = 0x04;

keymap\["KEY\_4"] = 0x05;

keymap\["KEY\_5"] = 0x06;

keymap\["KEY\_6"] = 0x07;

keymap\["KEY\_7"] = 0x08;

keymap\["KEY\_8"] = 0x09;

keymap\["KEY\_9"] = 0x0A;

keymap\["KEY\_0"] = 0x0B;

keymap\["KEY\_MINUS"] = 0x0C;

keymap\["KEY\_EQUALS"] = 0x0D;

keymap\["KEY\_BACK"] = 0x0E;

keymap\["KEY\_TAB"] = 0x0F;

keymap\["KEY\_Q"] = 0x10;

keymap\["KEY\_W"] = 0x11;

keymap\["KEY\_E"] = 0x12;

keymap\["KEY\_R"] = 0x13;

keymap\["KEY\_T"] = 0x14;

keymap\["KEY\_Y"] = 0x15;

keymap\["KEY\_U"] = 0x16;

keymap\["KEY\_I"] = 0x17;

keymap\["KEY\_O"] = 0x18;

keymap\["KEY\_P"] = 0x19;

keymap\["KEY\_LBRACKET"] = 0x1A;

keymap\["KEY\_RBRACKET"] = 0x1B;

keymap\["KEY\_RETURN"] = 0x1C;

keymap\["KEY\_LCONTROL"] = 0x1D;

keymap\["KEY\_A"] = 0x1E;

keymap\["KEY\_S"] = 0x1F;

keymap\["KEY\_D"] = 0x20;

keymap\["KEY\_F"] = 0x21;

keymap\["KEY\_G"] = 0x22;

keymap\["KEY\_H"] = 0x23;

keymap\["KEY\_J"] = 0x24;

keymap\["KEY\_K"] = 0x25;

keymap\["KEY\_L"] = 0x26;

keymap\["KEY\_SEMICOLON"] = 0x27;

keymap\["KEY\_APOSTROPHE"] = 0x28;

keymap\["KEY\_GRAVE"] = 0x29;

keymap\["KEY\_LSHIFT"] = 0x2A;

keymap\["KEY\_BACKSLASH"] = 0x2B;

keymap\["KEY\_Z"] = 0x2C;

keymap\["KEY\_X"] = 0x2D;

keymap\["KEY\_C"] = 0x2E;

keymap\["KEY\_V"] = 0x2F;

keymap\["KEY\_B"] = 0x30;

keymap\["KEY\_N"] = 0x31;

keymap\["KEY\_M"] = 0x32;

keymap\["KEY\_COMMA"] = 0x33;

keymap\["KEY\_PERIOD"] = 0x34;

keymap\["KEY\_SLASH"] = 0x35;

keymap\["KEY\_RSHIFT"] = 0x36;

keymap\["KEY\_MULTIPLY"] = 0x37;

keymap\["KEY\_LALT"] = 0x38;

keymap\["KEY\_SPACE"] = 0x39;

keymap\["KEY\_CAPSLOCK"] = 0x3A;

keymap\["KEY\_F1"] = 0x3B;

keymap\["KEY\_F2"] = 0x3C;

keymap\["KEY\_F3"] = 0x3D;

keymap\["KEY\_F4"] = 0x3E;

keymap\["KEY\_F5"] = 0x3F;

keymap\["KEY\_F6"] = 0x40;

keymap\["KEY\_F7"] = 0x41;

keymap\["KEY\_F8"] = 0x42;

keymap\["KEY\_F9"] = 0x43;

keymap\["KEY\_F10"] = 0x44;

keymap\["KEY\_NUMLOCK"] = 0x45;

keymap\["KEY\_SCROLL"] = 0x46;

keymap\["KEY\_NUMPAD7"] = 0x47;

keymap\["KEY\_NUMPAD8"] = 0x48;

keymap\["KEY\_NUMPAD9"] = 0x49;

keymap\["KEY\_SUBTRACT"] = 0x4A;

keymap\["KEY\_NUMPAD4"] = 0x4B;

keymap\["KEY\_NUMPAD5"] = 0x4C;

keymap\["KEY\_NUMPAD6"] = 0x4D;

keymap\["KEY\_ADD"] = 0x4E;

keymap\["KEY\_NUMPAD1"] = 0x4F;

keymap\["KEY\_NUMPAD2"] = 0x50;

keymap\["KEY\_NUMPAD3"] = 0x51;

keymap\["KEY\_NUMPAD0"] = 0x52;

keymap\["KEY\_DECIMAL"] = 0x53;

keymap\["KEY\_F11"] = 0x57;

keymap\["KEY\_F12"] = 0x58;

keymap\["KEY\_F13"] = 0x64;

keymap\["KEY\_F14"] = 0x65;

keymap\["KEY\_F15"] = 0x66;

keymap\["KEY\_KANA"] = 0x70;

keymap\["KEY\_CONVERT"] = 0x79;

keymap\["KEY\_NOCONVERT"] = 0x7B;

keymap\["KEY\_YEN"] = 0x7D;

keymap\["KEY\_NUMPADEQUALS"] = 0x8D;

keymap\["KEY\_CIRCUMFLEX"] = 0x90;

keymap\["KEY\_AT"] = 0x91;

keymap\["KEY\_COLON"] = 0x92;

keymap\["KEY\_UNDERLINE"] = 0x93;

keymap\["KEY\_KANJI"] = 0x94;

keymap\["KEY\_STOP"] = 0x95;

keymap\["KEY\_AX"] = 0x96;

keymap\["KEY\_UNLABELED"] = 0x97;

keymap\["KEY\_NUMPADENTER"] = 0x9C;

keymap\["KEY\_RCONTROL"] = 0x9D;

keymap\["KEY\_NUMPADCOMMA"] = 0xB3;

keymap\["KEY\_DIVIDE"] = 0xB5;

keymap\["KEY\_SYSRQ"] = 0xB7;

keymap\["KEY\_RALT"] = 0xB8;

keymap\["KEY\_PAUSE"] = 0xC5;

keymap\["KEY\_HOME"] = 0xC7;

keymap\["KEY\_UP"] = 0xC8;

keymap\["KEY\_PRIOR"] = 0xC9;

keymap\["KEY\_LEFT"] = 0xCB;

keymap\["KEY\_RIGHT"] = 0xCD;

keymap\["KEY\_END"] = 0xCF;

keymap\["KEY\_DOWN"] = 0xD0;

keymap\["KEY\_NEXT"] = 0xD1;

keymap\["KEY\_INSERT"] = 0xD2;

keymap\["KEY\_DELETE"] = 0xD3;

keymap\["KEY\_LWIN"] = 0xDB;

keymap\["KEY\_RWIN"] = 0xDC;

keymap\["KEY\_APPS"] = 0xDD;

keymap\["KEY\_ESC"] = KEY\_ESCAPE;

keymap\["KEY\_ENTER"] = KEY\_ENTER;

keymap\["KEY\_BACKSPACE"] = KEY\_BACK;

keymap\["KEY\_NUMPADSTAR"] = KEY\_MULTIPLY;

keymap\["KEY\_NUMPADMINUS"] = KEY\_SUBTRACT;

keymap\["KEY\_NUMPADPLUS"] = KEY\_ADD;

keymap\["KEY\_NUMPADPERIOD"] = KEY\_DECIMAL;

keymap\["KEY\_NUMPADSLASH"] = KEY\_DIVIDE;

keymap\["KEY\_UPARROW"] = KEY\_UP;

keymap\["KEY\_PGUP"] = KEY\_PRIOR;

keymap\["KEY\_LEFTARROW"] = KEY\_LEFT;

keymap\["KEY\_RIGHTARROW"] = KEY\_RIGHT;

keymap\["KEY\_DOWNARROW"] = KEY\_DOWN;

keymap\["KEY\_PGDN"] = KEY\_NEXT;

keymap\["MOUSE0"] = MOUSE0;

keymap\["MOUSE1"] = MOUSE1;

keymap\["MOUSE2"] = MOUSE2;

keymap\["MOUSE3"] = MOUSE3;

keymap\["MOUSE4"] = MOUSE4;

keymap\["MOUSE5"] = MOUSE5;

keymap\["MOUSE6"] = MOUSE6;

keymap\["MOUSE7"] = MOUSE7;

keymap\["MOUSE\_LEFT"] = MOUSE\_LEFT;

keymap\["MOUSE\_RIGHT"] = MOUSE\_RIGHT;

keymap\["MOUSE\_MIDLE"] = MOUSE\_MIDLE;

keymap\["KEY\_CONTROL"] = KEY\_CONTROL;

keymap\["KEY\_ALT"] = KEY\_ALT;

keymap\["KEY\_SHIFT"] = KEY\_SHIFT;

keymap\["ALT"] = KF\_ALT;

keymap\["CTRL"] = KF\_CTRL;

keymap\["SHIFT"] = KF\_SHIFT;

keymap\["DOUBLE"] = KF\_DOUBLE;

keymap\["\~ALT"] = KF\_NOALT;

keymap\["\~CTRL"] = KF\_NOCTRL;

keymap\["\~SHIFT"] = KF\_NOSHIFT;

keymap\["\~DOUBLE"] = KF\_NODOUBLE.

</details>

### **For Hotbar Actions**

`<&hotbar_key:anyAction>`

**Working Algorithm:**

* If the specified action is on the Hotbar, the game will display the corresponding hotbar key value in the text instead of the variable string.
* If the specified action is not on the Hotbar, the action hotkey value will be displayed if set.
* Otherwise, an empty value `[]` will be displayed.

## Example of using variable strings in localization

Fragment of a .lng file using variable strings:

{"02" "To build a breastwork, select your riflemen and press `<&hotbar_key:barricade>`. Then select a starting spot for the breastwork and press `<&mouse_action_key>`. Drag the mouse cursor to set the length for the fortification. Press `<&mouse_action_key>` again to order the breastwork to be built."

**Explanation of variables**

* `<&hotbar_key:barricade>`\
  This variable will be replaced by the key assigned to the `barricade` action in the hotbar. If the `barricade` action is assigned to a key, that key will be displayed. If not, it will display the hotkey for the action if set, or an empty value `[]` if neither is set.
* `<&mouse_action_key>`\
  This variable will be replaced by the mouse button configured for order issuance in the options window. By default, it is the right mouse button (RMB). If the "LMB orders" option is checked, it will be replaced by the left mouse button (LMB).

**Example user settings**

* Assume the `barricade` action is assigned to the key `F1` in the hotbar.
* Assume the mouse order button is set to the right mouse button (RMB).

**Resulting In-Game Text**

With these settings, the variables will be substituted as follows:

* `<&hotbar_key:barricade>` becomes `F1`.
* `<&mouse_action_key>` becomes `RMB`.

Thus, the text displayed in the game will be:

> To build a breastwork, select your riflemen and press `F1`. Then select a starting spot for the breastwork and press `RMB`. Drag the mouse cursor to set the length for the fortification. Press `RMB` again to order the breastwork to be built.

By understanding how the variables are substituted with actual key values set by the user, we can see how the text dynamically adapts to the player's configuration, ensuring that the instructions are always accurate and relevant to the current settings.

## **Configuration files**

| File name                  | Purpose                                                                                                                                      |
| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| keys.opt                   | Configuration of in-game actions to hotkeys                                                                                                  |
| scene\hud2\action.set      | File with descriptions of in-game actions                                                                                                    |
| interface\text#ingame+.lng | Localization file for in-game actions                                                                                                        |
| \*.lng                     | [Localization files](/documentation/foundational-knowledge/game-resource-architecture/package-file-structure.md#localization-folder-content) |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bestway-1.gitbook.io/documentation/localization/variable-strings-in-localization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
