Skip to content
vtcifer edited this page Feb 22, 2020 · 23 revisions

YAML Anchors

Anchors are an easy way to duplicate your content across your setup file. Use & to make an anchor and * to refer to it. The anchor(&) needs to appear above your reference(*).

Anchor: &my_anchor

Anchor reference: *my_anchor

The anchor MUST be on an earlier line than the reference.

Value Copying

You designate an anchor with the & character. The ampersand(&) acts as a label, referred to with the * character.

safe_room: &my_safe_room 1234
crossing_training_sorcery_room: *my_safe_room
outfitting_room: *my_safe_room

some_setting: &some_setting_anchor hunter2
another_setting: *some_setting_anchor

The next time you update your safe_room, you don't have to update the other settings that refer to it!

Dictionary Merging

You can use anchors to merge a set of values into another. You can merge a dictionary into another dictionary.

A dictionary looks like this:

waggle_sets:
  spell_set1:
  spell_set2:
  an_empty_set_of_spells:

You can put attributes in dictionaries. Attributes: name: Shadow noun: Moon book: true attributes_have_a: value

buff_spells:
  spell_1:
    mana: 12
  spell_2:
    mana: 3
    abbrev: spell2
  an_entry:
    in_a_dictionary: true

You can put anchors infront of those spells

buff_spells:
  spell_1: &anchor1
    mana: 12
  spell_2: &another_anchor
    mana: 3
    abbrev: spell2

You can refer to those spells via the anchors.

waggle_sets:
  spell_set1:
    << : *anchor1
  spell_set2:
    << : *another_anchor
    << : *anchor1
    some_other_spell:
      mana: 1
      abbrev: SoS

The above expands into:

waggle_sets:
  spell_set1:
    spell_1: &anchor1
      mana: 12
  spell_set2:
    spell_2: &another_anchor
      mana: 3
      abbrev: spell2
    spell_1: &anchor1
      mana: 12
    some_other_spell:
      mana: 1
      abbrev: SoS

Mechanical Lore Example

The script ;mech-lore.lic uses the setting hand_armor: gloves to figure out how to remove your hand armor to not be hindered while braiding. You set hand_armor: to the noun of the gloves you're wearing. Let's say you want to upgrade to fancier gloves, then you have to remember to change the hand_armor: setting if the new glove noun is different.

You can use the anchor/reference system to make this easier to change in the future. If you change hand armor, the mech lore setting automatically updates.

I've named the anchor 'hand_armor' because its the same as the setting that's using it.

gear:
- :name: &hand_armor gloves    
  :adjective: ring             
  :is_worn: true
       
hand_armor: *hand_armor

You can verify this correct by echoing the get_settings command in-game:

>;en echo get_settings.hand_armor  
--- Lich: exec1 active.            
[exec1: gloves]                    
--- Lich: exec1 has exited.

More Examples

https://github.com/rpherbig/dr-scripts/blob/aebd500279e7dbf1d56e3f92c1214308be7eee56/profiles/Crannach-setup.yaml#L9

https://github.com/rpherbig/dr-scripts/blob/aebd500279e7dbf1d56e3f92c1214308be7eee56/profiles/Crannach-setup.yaml#L391

Clone this wiki locally