Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What do the equals signs mean in multiple line comments? (see desc for details)

Asked by 5 years ago

I was wondering if anyone could explain to me what the equals signs mean in multiple line comments. eg. --[==[. I have looked on the roblox site however am confused with the term 'levels'.

2
that is used in if statements eg if game.Workspace.Gravity == 0 then, its not used anywhere else Gameplayer365247v2 1055 — 5y

1 answer

Log in to vote
0
Answered by
Rheines 661 Moderation Voter
5 years ago
Edited 5 years ago

When we usually end a multi-line comment using ]], we can accidentally end the comment (such as commenting out code that makes use of tables or dictionaries.)

Here is an example:

local list = {'a','b','c'}
local example = {a = 1, b = 2, c = 3}
--[[
while true do
    local var = example[list[1]] --The comment ends here.
    print(var)
    wait()
end
]]
print(true)

When we run this, we get an error: unexpected symbol near ']'

To leverage this situation, we can add an equal sign in the front and back (or more) to define a new delimiter to end the comment. The catch is that it needs to be have equal amount of signs in the beginning at the end.

local list = {'a','b','c'}

local example = {a = 1, b = 2, c = 3}

--[==[
while true do
    local var = example[list[1]] 
    print(var)
    wait()
end
]==] --Comment ends here now.

print(true)

When we run this, it prints as expected: true

If this answers your question, please accept this as the solution.

0
Thanks. Just what I was looking for. :) Sir_funnyguy 4 — 5y
Ad

Answer this question