Roblox > Scripting Lessons >

Proper Formatting

When writing your scripts, be sure to use proper formating. Using proper formating makes your scripts easier to read, and can save time later on.

The only real rule of formatting I can think of at the moment is using tabs to correctly space your scripts. When writing your scripts, place a tab before each line that is in between something that requires a end, and it's end. Place 2 tabs before the line if it is inside of two things that require an end. The best way to explain this is to give you an example.

bin = script.Parent -- There are no tabs here
if bin ~= game.Workspace then -- no tabs here either
if bin.Name ~= "base" -- notice that this line has a tab before it. this is because it is inside the if statement
-- notice that there is two tabs before this line
-- this is because it is inside the first if statement and inside the second if statment

The only problem is that you can not always format scripts this way. For example, it is difficult to send scripts in PMs with this formating. However, you should still try to use this formatting whenever possible. It makes scripts much easier for others to read and it can make it easier for you to find bugs in your code.
<- Lesson 11   What's Next ->
Updated on Oct 25, 2012 by Ajedi32 (Version 5)
comments powered by Disqus