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

{SOLVED}What is the difference between "==" and "=" ?

Asked by 10 years ago

{SOLVED}I am a new scripter, and i saw == and = in many scripts, so.. I want to know the difference between them and what are their functions....could anyone help??{SOLVED}

2 answers

Log in to vote
2
Answered by 10 years ago

'==' is used comparatively to check the equality of two values. If the two values are the same, then it will be true. For example:

local value1 = 2 * 5
local value2 = 20 / 2
print(value1 == value2) --True, because 10 == 10
--An alternate use using an if statement:
if value1 == value2 then
    print("Value1 is equivalent to Value2.")
end

'=' is used to assign a variable. Variables can be accessed throughout your script. Think it as giving something a nickname. Variables can hold all types of data, and unlike other programming languages you do not have to state the type of the variable being set. For example:

local variable1 = "Hello"
print(variable1) --Hello.

'=' can also be used to set properties of objects in your game. For example, you could set the name of a part to 'Hello, World' with the following:

Workspace.Part.Name = 'Hello, World'

It is easy to confuse the two, and if you do it can cause an error or majorly affect the function of your script. More information of both of these can be found in the Scripting Glossary

Ad
Log in to vote
3
Answered by 10 years ago

You use a single equals sign when you want to set the value of something, such as a variable or property. A double equals sign is used when you want to compare something. Double equals signs are used in conditionals such as the following. If you tried it with a single equals sign it would error because you'd try to be setting the value of something rather than checking the value.

This is an example of each:

function example()
    if 1 + 2 == 3 then -- comparing to see, is 1 + 2 equal to 3?
        game.Players.LocalPlayer.Name = "Waldo" -- setting the player's name to Waldo
    end
end

example()
0
upvoted for the 2 of you guys :D kudorey619 138 — 10y

Answer this question