1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to get indentations right

Oct 24, 2019
How to get indentations right
  • In this small page, I will explain indentation.

    What is indentation?
    indentation is "the action of indenting or the state of being indented"
    indent is "start (a line of text) or position (a block of text, table, etc.) further from the margin than the main part of the text."
    Simply, when you want to make a block of code, you need a new indentation

    in programming, indentations are tabs
    Skript allows a variety of indentation methods
    - 1 tab
    - 4 spaces
    - 2 spaces

    it is recommended to use 1 tab but if you cant use 1 tab, use 4 spaces.
    2 spaces are also valid but it is not recommended.
    (in atom text editor, the tab defaults to 2 spaces. you can change this in settings)

    example

    Code (Text):
    1.  
    2. set {_n} to 1
    3. loop 10 times:
    4. # starting a code block
    5.     add 1 to {_n}
    6.     broadcast "the current number is %{_n}%"
    7. broadcast "the final number is %{_n}%"
    because of the indentation, the code flows like this
    [​IMG]


    the block inside Loops and when the loop is over it goes outside and continues the code


    When should I use indentation?

    Every time you use a ":" at the end
    except using short hand if
    ex)
    https://skriptlang.github.io/Skript/conditions.html
    they look like these
    {var} is 1
    event-item is diamond pickaxe

    they are a shorthand expression for
    if the condition is false:
    stop this code
    so you don't need an indentation.

    adding a ":" will allow an else(and "else if") expression

    example of a valid indentation

    Code (Text):
    1. command /test:
    2.     trigger:
    3.         tool of player is dirt
    4.         send "you have dirt"
    5.  
    6. command /test2:
    7.     trigger:
    8.         tool of player is dirt:
    9.             send "you have dirt"
    10.  
    11.  
    12. command /test3:
    13.     trigger:
    14.         if tool of player is dirt:
    15.             send "you have dirt"
    16.  
    example of an invalid indentation
    Code (Text):
    1.  
    2. # will throw an indentation error
    3. command /test:
    4.     trigger:
    5.         tool of player is dirt
    6.             send "you have dirt"
    7.  
    8. # will suppress the error.
    9. command /test2:
    10.     trigger:
    11.         tool of player is dirt:
    12.         send "you have dirt"
    13.  
    14.  
    15.  
    edit 19/10/20 i got 1 statement wrong.
    updated the article accordingly
    sorry for my mistake
    edit 19/10/24
    added some more information