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

What is the difference between a string and a variable?

Asked by 6 years ago

I do not understand the difference. They both seem the same to me, they both hold data.

0
a string value has strings whereas a variable can hold strings, numbers, almost anything... greatneil80 2647 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

They are a big difference. So, let me teach you about them.

Variables

Variables are things that can be used for later. So, instead of typing this

print('spam')
print('spam')
print('spam')
print('spam')
print('spam')
print('spam')
print('spam')
print('spam')
print('spam')
print('spam')

you could use variables!

local p = print
local s = 'spam'
p(s)
p(s)
p(s)
p(s)
p(s)
p(s)
p(s)
p(s)
p(s)
p(s)

Strings

Strings are basically text that you don't want roblox to run as actual code. For example, this would error

print(game.sometext)

because sometext is not a member of game. So, to tell the program "Hey, I don't want this code to run", we do

print('game.sometext')

Hope this helps!

0
Also, you cannot hold terrain in a string. hiimgoodpack 2009 — 6y
Ad
Log in to vote
2
Answered by
lukeb50 631 Moderation Voter
6 years ago
Edited 6 years ago

First off, Here is a page I think you may find useful

A variable holds data that can be of any kind. A string is a kind of data that holds text. Other kinds of data are Integers(Number) and Boolean(Logic:True/False). So in other words, a variable can be a string but a string cannot be a variable

Log in to vote
-1
Answered by
R_alatch 394 Moderation Voter
6 years ago
Edited 6 years ago

Variable

A variable is a name you can use to hold a value. In Lua, a variable can have any data type, such as a number or a string. See here

String

Strings are sequences of letters, numbers, and symbols. See here

0
Your definition for string is not helpful. hiimgoodpack 2009 — 6y

Answer this question