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

Why do we need to put == instead of = , isnt it the same?

Asked by 5 years ago
Door = game.Workspace.Wall

function pie()
    if Door.Transparency == 1 then
        Door.Transparency = 0
    else
        Door.Transparency = 1
    end
end

script.Parent.ClickDetector.MouseClick:Connect(pie)

"if Door.Transparency == 1 then"

Why not just "="?

0
But why? What if I want to compare with =? Code doesn't read your mind. I wasn't asking you directly btw. pls don't forget to accept answer if i helped programmerHere 371 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago

Because Lua syntax.

= and == are two different operators and do different things. The former assigns a variable or table field to a value. The latter compares two given values, and returns true if they are raw equal, or equal via __eq.

Plus it could be ambiguous, do you want to assign Transparency to 1 or compare it to 1?

0
But why? What if I want to compare with =? Code doesn't read your mind. I wasn't asking you directly btw. programmerHere 371 — 5y
0
You can't compare with =. It would be way too confusing flashdrive284 0 — 5y
0
You can't compare with = because it will break things. = initializes/assigns a value to a variable/read above. == checks if thing is equal to thing2 (look at explanation above) Robin5D 186 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Code language creators wanted to have a difference between the two since it would confuse the computer. We use = for assigning a value, and == for comparing a variable.

Log in to vote
0
Answered by
VitroxVox 884 Moderation Voter
5 years ago
Edited 5 years ago

Well i see a lot of people has already answered this question but i don't see any quick and short explanation so here:

Basically = is used for setting something example as:

game.workspace.part.Name = "test" or game.workspace.part.Parent = game.ReplicatedStorage or *game.Players.Zetruis.Leaderstats.Money.Value = 1000"

and the list goes on.

The == is used to define is something equals to something example as:

if game.Players.Zetruis.Name == "Zetruis" then print"okay its him" end or if (5+10) == 15 then print"ok" end

and of course the list goes on.

Answer this question