-
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
-
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):- set {_n} to 1
- loop 10 times:
- # starting a code block
- add 1 to {_n}
- broadcast "the current number is %{_n}%"
- broadcast "the final number is %{_n}%"
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):- command /test:
- trigger:
- tool of player is dirt
- send "you have dirt"
- command /test2:
- trigger:
- tool of player is dirt:
- send "you have dirt"
- command /test3:
- trigger:
- if tool of player is dirt:
- send "you have dirt"
Code (Text):- # will throw an indentation error
- command /test:
- trigger:
- tool of player is dirt
- send "you have dirt"
- # will suppress the error.
- command /test2:
- trigger:
- tool of player is dirt:
- send "you have dirt"
updated the article accordingly
sorry for my mistake
edit 19/10/24
added some more information