User:JulienDethurens/Guide/Chapter 4
This page talks about some subjects that could be useful to know about. You can read these at any time, there is no specific moment to read them, so you don't need to read them completely at the end. However, some of these assume you have some prerequisite knowledge, so you might only be able to understand some of these after reading a certain part of the guide.
Indentation
Indenting code means using tabs (or spaces, but I prefer tabs) to indent code, to make it more organized.
Usually, a new level of indentation is added on every new block of code, or every scope, if you prefer. Some also do it for tables and in long comments.
Here is an example of indented code (note: it will look different in the studio's script editor, because the tab width here is way too big. In the studio's script editor, the tabulations will look smaller and it will look better):
for i = 1, 50 do
if math.random(5) == 3 then
print(string.format("The number is %d.", i))
elseif math.random(15) == math.random(10) then
print(math.random(5) + i)
break
end
end
And here is the same code, without indentation:
for i = 1, 50 do
if math.random(5) == 3 then
print(string.format("The number is %d.", i))
elseif math.random(15) == math.random(10) then
print(math.random(5) + i)
break
end
end
Indented code looks much better than non-indented code. Indenting it will make it much more organized and will be extremly helpful later on, when you'll want to edit your code and understand it faster. Trust me, you should always indent code, even if you think it's not worth it.