Since there are a lot of people who don't understand how to tab, I decided to make a little tutorial about it and I hope it's clear enough like this.
Why is it important to tab scripts?
Tabbed scripts more easy to read and understand.
Within a few seconds people can find a missing end in a tabbed script, in a script that is not tabbed this can take hours (people will probable just tab the script instead).
Same goes for other problems. With tabbed scripts it's really clear which part belongs to what and this is needed to solve problems with scripts.
Also for yourself, you won't have problems with missing ends, to much ends or Lua functions in the wrong place if you tab your scripts, because in a few seconds you can see what's wrong.
There are several things in Lua that need an end to close it, for that you have to use tabs.
Most used ones in OT scripts are function, if and for, they all close with the word end.
There is also while (end) and repeat (until).
I will use function onUse, if and for as example.
I will start with the function.
After you wrote the function, in the next line you press Tab (above Caps Lock) before you write a new line.
Under that the end should be right under the function.
Now there will be a space between the function and the end that closes the function.
You can see the space as "property" of the function, you can't write anything in that space untill the end that closes it.
The green stripe here is the space of the function.
Like function, also an if statement needs an end to close it.
So after you write a line that starts with if, next line you need to tab again.
The yellow stripe here is the space of the if statement.
After an if statement, you can write else, for something that will happen if the if statement is not true.
So else is a part of an if statement and should be in the space of the if statement. The rest still can't be in that space.
Same goes for elseif, which works similar to else except that it's more like an if statement.
I also added a magic effect to show you have to write anything right under it, as long as it's not in the space of an if statement or the function.
When function or an if statement closes with end, everything under it is not in their space anymore, so you have to write it right under the end without making a new tab.
The dark yellow stripe here is the space of the second if statement.
When you have an if statement inside an if statement, it will be the same thing, after the second if statement, you press tab again so the second if statement will have it's space inside the first if statement.
The orange stripe here is space of the second if statement (third in total).
A for loop also closes like function and if with the word end.
It is often used in combination with tables, but if you do it like this it will just repeat everything till the end 3x (1,2,3 = 3x).
Also here it's important to see here where it ends, because if you add for example the textmessage above the end, you will get this message 3x.
The red stripe here is the space of the fourth if statement and the purple stripe the space of the for loop.
If you have questions or things still aren't clear enough, let me know.
Why is it important to tab scripts?
Tabbed scripts more easy to read and understand.
Within a few seconds people can find a missing end in a tabbed script, in a script that is not tabbed this can take hours (people will probable just tab the script instead).
Same goes for other problems. With tabbed scripts it's really clear which part belongs to what and this is needed to solve problems with scripts.
Also for yourself, you won't have problems with missing ends, to much ends or Lua functions in the wrong place if you tab your scripts, because in a few seconds you can see what's wrong.
There are several things in Lua that need an end to close it, for that you have to use tabs.
Most used ones in OT scripts are function, if and for, they all close with the word end.
There is also while (end) and repeat (until).
I will use function onUse, if and for as example.
I will start with the function.
After you wrote the function, in the next line you press Tab (above Caps Lock) before you write a new line.
Under that the end should be right under the function.
Now there will be a space between the function and the end that closes the function.
You can see the space as "property" of the function, you can't write anything in that space untill the end that closes it.
The green stripe here is the space of the function.
Like function, also an if statement needs an end to close it.
So after you write a line that starts with if, next line you need to tab again.
The yellow stripe here is the space of the if statement.
After an if statement, you can write else, for something that will happen if the if statement is not true.
So else is a part of an if statement and should be in the space of the if statement. The rest still can't be in that space.
Same goes for elseif, which works similar to else except that it's more like an if statement.
I also added a magic effect to show you have to write anything right under it, as long as it's not in the space of an if statement or the function.
When function or an if statement closes with end, everything under it is not in their space anymore, so you have to write it right under the end without making a new tab.
The dark yellow stripe here is the space of the second if statement.
When you have an if statement inside an if statement, it will be the same thing, after the second if statement, you press tab again so the second if statement will have it's space inside the first if statement.
The orange stripe here is space of the second if statement (third in total).
A for loop also closes like function and if with the word end.
It is often used in combination with tables, but if you do it like this it will just repeat everything till the end 3x (1,2,3 = 3x).
Also here it's important to see here where it ends, because if you add for example the textmessage above the end, you will get this message 3x.
The red stripe here is the space of the fourth if statement and the purple stripe the space of the for loop.
If you have questions or things still aren't clear enough, let me know.
Last edited: