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

Why in script tho we ad a ‘ at the end and start of what string and why we use them?

Asked by
BIGM_7 4
4 years ago

I am having trouble with strings and I can’t figure out this script.

0
Can you post the script? GeneratedScript 740 — 4y
0
You can use either ' or " to tell the script that you're making a string. Usually ' is for characters and " is for strings in other languages so I'd go by that rule. royaltoe 5144 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

Hello!

We use ' and " at the beginning and end of strings to tell if it's a variable or a string. So it is used not to confuse the computer so they can know if it means string or something else.

An example:

local variable = "hello"

print("variable") --this will print the text 'variable' and not 'hello' since the quotation marks mean string and not getting the actual variable.

print(variable) --this will print 'hello' since there are no quotation marks so it gets the variable called variable instead.

Hope this helps.

Ad
Log in to vote
-1
Answered by
haba_nero 386 Moderation Voter
4 years ago
Edited 4 years ago

Hello kind sir.

As described above in the other answer. Variables and strings are very cool. But the important thing to know is to put these tags "" between variables. The reason why you should do this is that the game can confuse strings with actual objects! let's see an example!

local string = "hello!"
local hello = nil

print("hello!")--This will print hello with no problems
print(string)--this will print a connected string. Use no tags because this is an ob
print(hello)--This will attempt to print a nil value, which is impossible because nil means nothing
--Therefore, this part will result in a script crash

Hope this helps you!

Best

TheLastHabanero

0
-1 for "This will attempt to print an object from the workspace, which is impossible", and "Therefore, this part will result in a script crash". Do you know anything about metamethods? programmerHere 371 — 4y
0
Ok I changed it. You happy? haba_nero 386 — 4y
0
Dont be salty ok? haba_nero 386 — 4y

Answer this question