Clarify some YAML related things please

n0nnie

Active member
I recently bumped into some Questions, which might be handy for further readers:

This tells me:
» Use to modify a YAML file similarly to a flag.
- yaml id:myfile set my.key[2]:hello

But if I do something like this:
Code:
- yaml id:tablist_config set tablist.header.text:Zeile1
      - yaml id:tablist_config set tablist.header.text[2]:Zeile2

A yml file is created, where Zeile1 is overwritten with Zeile2 and i looks like this:
Code:
tablist:
  footer:
    text:
    - Zeile2

Can I do something like this and if, how?
Code:
tablist:
  footer:
    text:
    - <&f>--------------------------------
    - <&5>   www.uhu-uhu.de
    - <&5>   Eulen, die ranklotzen

Next question I ran into:
Is there some way to force a sorting order? The creation of the yaml files seems a bit random to me. It does not seem to sort it in any way?

Last question:
Is there a way to put some sort of comment into the default config file? Maybe I can make it looking like this:
Code:
tablist:
  footer:
    text:
    #Here you can specify your footer. Each line will be a new line. Color codes have to be like <&code>
    - <&f>--------------------------------
    - <&5>   www.uhu-uhu.de
    - <&5>   Eulen, die ranklotzen
 

mcmonkey

Administrator
Staff member
Helper
n0nnie said:
Can I do something like this and if, how?
That appears to actually be a bug in the YAML handler in Denizen. That bug is fixed in build DEV-603+ :D
Thanks for pointing that out!

n0nnie said:
Is there some way to force a sorting order? The creation of the yaml files seems a bit random to me. It does not seem to sort it in any way?

You can sort the list of keys when looking at it via tags, like "list.alphanumeric". Keys beyond that are not inherently sorted and will not remain in any specific order while in YAML. YAML does not order keys, only lists in YAML are ordered.

n0nnie said:
Is there a way to put some sort of comment into the default config file? Maybe I can make it looking like this:

Only if you distribute the config file as text or include it directly inside the script (via 'yaml data' script type!)
YAML does not retain knowledge of comments when loading/saving.