Logic in Lua, while very understandable (Using "or" and "and" instead of && and || like in other languages), still can't just be read like normal english. This is because like in math, logic equations both need to be in terms of true/false and follow an order of operations.
For example, solve this: (22 + bannana) * 102 - lol. That doesn't make sense, does it? In math, we need numbers and only numbers. Same thing for logic equations, except instead of numbers we need booleans, which are just special data types that can be either true or false (In the same way a number can be 1, 2, 3, 4... etc.). The special thing about booleans and logic equations, however, is that by using specific operators (Like '+' and '-' in math) we can use almost any arbitrary data as an input to the equation. The operator for this is usually '==', which checks for equality. For example:
local boolean1 = "String1" == "String1"
local boolean2 = "String1" == "String444"
This is cool because we can convert strings (As well as other types of data) into a true/false value, which can be used in an if or while statement to control flow.
What's also important here is that, without that '==' converting our strings to booleans, a string is just a string. Let's run through a complex example boolean problem that has an error. (I've used numbers, but you could also use strings or anything else)
local mysteryBool = (input == 1 or 2 or input > 100)
Let's assume input is 1. How does this solve out?
(1 == 1 or 2 or input > 100)
(true or 2 or input > 100)
(true or 2 or false)
There's a problem here. Now we're trying to compare true and 2, which doesn't make any sense. That's because we never converted 2 to a boolean using ==. Here's the problem rewritten correctly.
local mysteryBool = (input == 1 or input == 2 or input > 100)
Let's solve it, again using 1 as input.
(1 == 1 or 1== 2 or input > 100)
(true or input == 2 or input > 100)
(true or false or input > 100)
(true or false or false)
(true or false)
(true)
And there you go, it works.
In conclusion, remember to always convert your data to booleans before trying to compare with "or" or "and". When in doubt, try to solve through your logic equations using a test value.
--Edit: Changed capitalization of Lua
1 comment
do.... if v.Name == "Main" or v.Name == "Sides" then