
This will be short and sweet. Anyone who is new to coding might know about leaving comments in your code. Those who have coded for awhile know it’s vital to leave comments to your future self at the very least.
Another great use for comments is blocking out code from running. This is where the absolute magic of Lua comments come in.
-- Whole Line Comment
x = 10 -- Inline Comment
print(x)
> 10
Any time there is two dashes, the rest of the line becomes a comment.
There’s also the [[ ]] operator. Use [[ ]] instead of “ “ to make a multi-line string.
long_string = [[For instance, on the planet Earth, man had always assumed that he was more intelligent than dolphins because he had achieved so much—the wheel, New York, wars and so on—whilst all the dolphins had ever done was muck about in the water having a good time. But conversely, the dolphins had always believed that they were far more intelligent than man—for precisely the same reasons.]]
print(long_string)
>For instance, on the planet Earth, man had always assumed that he was more intelligent than dolphins because he had achieved so much—the wheel, New York, wars and so on—whilst all the dolphins had ever done was muck about in the water having a good time. But conversely, the dolphins had always believed that they were far more intelligent than man—for precisely the same reasons.
Now, let’s combine these elements to make a multi-line comment
--[[ This is a long comment
anything in between these brackets is commented out
x = 10
and now we can end the long comment.]]
print(x)
> nil
THE MAGIC
--[[ Start your block comment with this
and make the very last line look like this:
--]]
Now why would we put dashes inside the comment block?
--[[ This is code that will not run. It's a big block comment
x = 10
x = x + 10
--]]
---[[ This is code that WILL run.(Everything after -- is commented out)
y = 10
y = y - 10
--]] This is just a blank commented line.
print(x)
> nil
print(y)
> 0
You can create big chunks of blocks that “turn on and off” by adding/removing a SINGLE dash from the start of the block.

Absolutely beautiful design.
10/10
no comments
Until Next Time,
Lodomo

Leave a Reply