Tutorial by: Olyno


skript-yaml in 5 minutes

It is important to note that this tutorial will not enter into the complex, and will remain on the basic. To go into the complex, I invite you to go to the syntaxes of the addon and ask for help on forums or Discord about it.

skript-yaml is an addon as its name indicates it designed to manage YAML files (.yaml/.yml). It works with a cache system.

What is "cache"?

Imagine you have to go back and forth from one room to another to transfer boxes. You will leave the door open so that you don't have to reopen it every time. The cache is the same. You will open the door once, transfer the cardboard and close it again (optional).

Loading a YAML file

Well, if you entered the cache system you got off to a good start. Here the door will be the effect:

load yaml "plugins/Mon fichier yaml.yml" as "test"

Here as "X" is the choice of the identifier of your file where X is the name of the identifier.

There is no point in loading the same file 50 times. It's like wanting to open an already open door 50 times. This is why this effect must be placed in the right place:

If the yaml file does not exist, skript-yaml will create it, this includes the folders.

The "unload" effect will only be used if you load too many files. Back up your data before using it (see below).

Getting, Adding and Setting Values

To put values into the YAML, you have a choice between list and value. The lists are several values, so you can modify the lists using add and remove. The values are only one value, therefore can only be modified using set.

Syntax:

yaml (list|value) "root node.node.value" from "votre fichier yaml ou identifiant"

It is an expression.

It is important to note that skript-yaml pays attention to types, i.e. what to do:

set yaml value "test" from "config" to "true"

is by no definition not the right method. In this example, the correct method would be:

set yaml value "test" from "config" to true

It will be exactly the same with number, location, item etc...

You can get a value too:

set {_test} to yaml value "test" from "config"

Example:

on script load:
    load yaml "plugins/skript-yaml/teleport.yml" as "plugins/skript-yaml/teleport.yml"

command /savetp:
    trigger:
        set yaml value "%player%.location" from "plugins/skript-yaml/teleport.yml" to location of player
        save yaml "plugins/skript-yaml/teleport.yml"

command /tp:
    trigger:
        teleport player to yaml value "%player%.location" from "plugins/skript-yaml/teleport.yml"

I don't see the values updated in the file, normal?

Yes, the values are modified in the cache. This means that the changes will be available until the cache is cleared by the application in question (here it will be your server). To save your data, you just need to use:

save yaml "identifier"

Use this effect only when you have made all the changes. Otherwise it would be like closing the door after passing each box, it wouldn't make sense.

Example:

save yaml "config"

How can I add comments to my file?

There is an expression for that. It is:

comments of yaml node "root node.subNode.node" from "identifier"

Comments cannot be applied only to root nodes as in the syntax above.

However, they can be applied at the top of your file using:

comments at the top of "identifier"

Examples:

set the comments of yaml node "test" from "config" to "First line" and "Second line"
delete the comments of yaml node "test" from "config"

set {_at the top::*} to "First line" and "Second line"
set the comments at the top of "config" to {_at the top::*}
delete the comments at the top of "config"

set the header of "config" to "First line" and "Second line"
delete the header of "config"
set the header of "config" to {_at the top::*}

======= Resources =======

Link to the addon: https://github.com/Sashie/skript-yaml

SkriptHubViewTheDocs


Did you find Olyno's tutorial helpful?


You must be logged in to comment