Tutorial by: Blueyescat


Reading Syntaxes / Patterns

A syntax defines the ways to use a Skript code. If the code you use in your script doesn't match with any syntax, it will fail to load and give you errors.

Lets use the syntax of the Make Say effect as an example:

make %players% (say|send [the] message[s]) %strings%
force %players% to (say|send [the] message[s]) %strings%

Yes, it has multiple syntaxes! You can use any syntax you want. Now lets explain how to read them:

  1. The parts that are not between something means you must use them in your code
  2. The parts between brackets [ ] are optionals
  3. The parts between parentheses ( ) are options
  4. The parts between percents % % are expressions

Note: It is possible to have options in optionals, optionals in options, expressions in options/optionals. You can see that we have optionals in options in our example syntax.

Optionals

Simply means you can include the thing between brackets in your code if you want.
With our example syntax, these will work: message, the message, messages and the messages

Options

Options are separated by vertical bars |, this means you can use any option you want. It is easier to understand it from our example syntax: (say|send) means you can use say or send in your code.

Expressions

Expressions in syntaxes simply means user input.

In our example %players% means you need to reference/enter one or more player objects. If the expression was single like %player%, then you wouldn't be able to enter multiple players.
%strings% means you need to enter one or more texts/strings to this part.

object type would mean you can enter anything you want.
classinfo type would mean you need to enter a type, like on the Parse expression: "1" parsed as number

Expressions can have multiple types, separated by a slash character /:
%entity/itemtype% simply means you can enter an entity or an item to the expression.


You should always check examples of the syntax if you still don't understand how to use the syntax.

Lets make a ready to use code from the syntax

force all players to send messages "message 1", "message 2" and "message 3"

Used syntax: 2



Other Good to Know Things

Direction - Location Combination

spawn %entitytypes% [%directions% %locations%]
spawn %number% of %entitytypes% [%directions% %locations%]

If a syntax like this uses %directions% %locations%, you can enter "at" to the direction expression. This is how it is possible to use these:

spawn a zombie at the player
spawn a zombie behind the player

And as you can see, there are type converters in Skript. You can enter an entity to a location expression, so it will use location of the entity.

Regex Inputs

You will rarely see things between less/greater than symbols < > in some syntaxes, they mean you can enter anything that matches the regex between to this part. If you see a regex input in a syntax, you should always check its example codes to understand how it works.

As an example, see the syntax of the Ternary expression:

%objects% if <.+>[,] (otherwise|else) %objects%

In the regex, '.' matches with any character expect line breaks, '+' matches with one or more of '.'. So, basically '.+' means it accepts everything. But this doesn't mean that Skript can't check the input, the Ternary expression limits the input to a condition. So it will give error if you don't enter a correct condition.
Example usage:

broadcast "x is set" if {x} is set, else "x is not set"
#                       ^ '{x} is set' is the input to the regex

Did you find Blueyescat's tutorial helpful?


You must be logged in to comment

  • Dec. 9, 2020, 5:11 a.m. - TomatoNNNN  

    can you explain what does * and - means for example in the expression
    [the] target[[ed] %*entitydata%] [of %livingentities%]
    what is the difference %*entitydata% and %entitydata%
    and for the tablisknu expression
    (line %-number%|[the] last line) of [the] tablist (header|footer)[s] [(for|of) (%-players%|group %-string%)] what does the - mean

    |     
    June 28, 2022, 4:36 p.m. - Kiip  
    • means nullable, * means static only
    |