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 11 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 11 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:

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

'=' 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:

1local variable1 = "Hello"
2print(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:

1Workspace.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 11 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:

1function example()
2    if 1 + 2 == 3 then -- comparing to see, is 1 + 2 equal to 3?
3        game.Players.LocalPlayer.Name = "Waldo" -- setting the player's name to Waldo
4    end
5end
6 
7example()
0
upvoted for the 2 of you guys :D kudorey619 138 — 11y

Answer this question