Formatting helps you read your code better and helps you skim. It helps you learn where to place your ends and also commonly helps you know if there's an end missing, as any block that creates a new end keyword also requires an extra 8-width tab.
Think of it like this, right:
function doThisCode(...)
if ... then
print("yes")
end
if otherthing then
print("no")
Character:SetPrimaryPartCFrame(
CFrame.new(
0,
15,
0
)
)
end
end
looks fairly awful, doesn't it? Now, let's look at it with indentation:
function doThisCode(...)
if ... then
print("yes")
end
if otherthing then
print("no")
Character:SetPrimaryPartCFrame(
CFrame.new(
0,
15,
0
)
)
end
end
Looks better. Now, let's say you have screwy indenting and you're, let's say, missing an end on a connection:
PlayerAdded:Connect(function(Player)
function doThisCode(...)
pcall(function()
if ... then
print("yes")
end
if otherthing then
print("no")
Character:SetPrimaryPartCFrame(
CFrame.new(
0,
15,
0
)
)
end
end
end
Player.CharacterAdded:Connect(function()
doThisCode()
end)
end)
Where are you going to find the error without compiling? It looks terrible!
Now once we visualize the code in a better-indented form:
PlayerAdded:Connect(function(Player)
function doThisCode(...)
pcall(function()
if ... then
print("yes")
end
if otherthing then
print("no")
Character:SetPrimaryPartCFrame(
CFrame.new(
0,
15,
0
)
)
end
end
end
Player.CharacterAdded:Connect(function()
doThisCode()
end)
end)
Oh wowie, we can tell that the pcall function isn't closed because we know that I gave it an anonymous function but we didn't close the parenthesis to supply it as an argument! We can tell because the ends line up very well, but there's no parenthesis meaning that it would error.
tl;dr it's just better to read and it helps debugging become alot quicker
1 comment
Wow! That must of took a lot of effort, thanks!!