Hello everyone, I was stumbling around on some scripts and I saw some scripts like,
d.Text = [[ Hello, world! ]]
or something where you can even read what is inside of it.
If anyone knows what I am talking about, please let me know.
Hello everyone, I was stumbling around on some scripts and I saw some scripts like,
d.Text = [[ Hello, world! ]]
or something where you can even read what is inside of it.
If anyone knows what I am talking about, please let me know.
idk but i think its another way like to create a string or smth like this (“Hello, world”)
or a different coding language im not sure
Oh, so what is the difference between the double square brackets and strings?
square bracks are also used if you using a variable and then say something after that variable?
for example
RepStorage = game.ReplicatedStorage
RepStorage["Gun"]
Ill tell you more later
This is useful when you have a special character in the instance’s name. For example, if you have a part called “Car Door”, you can’t just write it like Model.Car Door
, because you can’t have a space inside a line. Instead, you use it like Model["Car Door"]
(without the period, with the brackets), and the script will accept it.
Also, when lets say using a reserved keyword (such as CFrame) in a tween. Instead of
tween = TweenService:Create( ... , {CFrame = CFrame.new()})
you do
tween = TweenService:Create( ... , {["CFrame"] = CFrame.new()})
because CFrame
is a reserved keyword, so you cant leave it alone.
No but like, some people use this:
[[ ]]
Instead of just [].
That just means it’s a string, so basically
[[Hello World]]
is the same as
"Hello World"
[[ ]]
is used to make a multi-line string. Nothing more.
That is completely wrong lol. workspace[“Part”] works only cuz the workspace is a huge dictionary you are reading.
(To say it dumb)
Same for
--[==[
Multi-line comment-
here
]==]
In luau it lets you create a multiline string. Usually it is unused in favour for single line strings created by " quotation marks ".
its not wrong at all go on try it
You don’t even need [[ ]].
[[Hi
this is multiple lines
wsg]]
is the same as
"Hi\nthis is multiple lines\nwsg"
It usually means multiple lines, like in Luau, you can use stuff such as multi line quotes, and you can also use it for multiline comments.
That is much more messier though.
The difference is that “[[” and “]]” are strings that can contain newlines, just like what @GamersInternational said.
whats the point of doing that what good does it do
[[ ]] means json, or can be used for multiple lines of a string
I use them for just putting strings in a ModuleScript and then just requiring it to get a single string.
Well, it’s a very long string. Don’t judge me.
Yeah, I think that’s more accurate.
It’s just a way of writing strings with more exceptions. For example, if you want to use the same quote characters within a string, you have to escape it with \
:
local foo = "And his name is \"John Cena\""
--or use the other quote character to disambiguate
local foo = 'And his name is "John Cena"'
However, it can be simplified with the double-bracket notation:
local foo = [[And his name is "John Cena"]]
print(foo) --> And his name is "John Cena"
But what if you want to do all of the above, including using the double-bracket notation as the string?
local foo [=[
[[And his name is "John Cena"]]
]=]
print(foo) --> [[And his name is "John Cena"]]
This pattern of adding equal signs to differentiate the brackets continues. You can add as much as you want.
loadstring[============[
loadstring[===========[
loadstring[==========[
loadstring[=========[
loadstring[========[
loadstring[=======[
loadstring[======[
loadstring[=====[
loadstring[====[
loadstring[===[
loadstring[==[
loadstring[=[
loadstring[[
print'And his name is "John Cena"'
]]()
]=]()
]==]()
]===]()
]====]()
]=====]()
]======]()
]=======]()
]========]()
]=========]()
]==========]()
]===========]()
]============]()
Readability; Would you rather:
local var = [[
This
is
a
string
that
spans
multiple
lines
]]
or
local var = "this\nis\na\nstring\nthat\nspans\nmultiple\nlines"