When you say:
something = somethingelse
The thing on the right side of the equals can be only a few specific things:
- A number (not in quotes)
- A string (which has to be enclosed in quotes)
- Another variable (a string not in quotes)
- boolean: true or false (not in quotes)
- nil (meaning empty… not in quotes)
- a table enclosed in curly braces {}. Curly braces with nothing in between is an empty table.
- A function (this is getting beyond the scope of this post)
when you say:
this = yes
It makes the variable this contain the value held in the variable yes. The variable yes has not bee defined, so it defaults to nil. So in effect you just said
this = nil
If your intent was for this to hold the string “yes”, you need quotes:
this = “yes”
Now inside your function, you are using an If statement and doing a comparison and asking:
is this equal to (==) yes? This condition is true since yes is nil and you assigned nil to the variable this.
is thisAlso equal to no? This conditions is also true, since thisAlso holds the same value as the variable no, which is undefined of nil. So the total test resolves to:
if true and true then
which is a true condition and your statement prints.
Now if you rewrote this:
this = "yes" thisAlso = "no" function test() if this == "yes" and thisAlso == "yes" then print ("THIS SHOULDN'T PRINT") end end