No grammar found. Anyways, what I was trying to say in the title is how would I make one of the "equal to" statements accept two possible values. Here is an example:
If v == random1 or v == random2 then
However, I wanted to know if there was a way I could combine the two. As in have one equal to statement with two possible values (Ie. V == random1 or random2; something like that). How would I do this?
You are completely correct. Use the or
operator.
Like not
or and
, the or operation in if then statements will see if something will equal this, OR if it will equal something else:
local a = 2 local b = 1 if a < 1 or b > 0 then print("1 of these are true") --2<1 is not true, but 1>0 is, so the script runs anyway. end
You could also use and
, which would need BOTH of the statements to be true:
local a = 2 local b = 1 if a > 0 and b< 9001 then print("Both are correct!") --If one of those 2 statements are false, the script doesn't run. end
Also not
is kinda like ~=. It means not true or does not equal this:
local test = "LordDragonZord" if not test == "Bob" then print("LordDragonZord is not Bob.") end
It runs because it is saying: "If LordDragonZord does NOT equal Bob then..."
Hope this helps!
if v.Name == 'Hi' or 'Hi' then -- the first argument checks for `v`'s Name property, --while the second only checks if `string`.
All conditions are defaulted to true unless explicitly false or nil. In the code you have provided, your second operand
is not a comparison and is also not nil or false, therefore is true.
So, even if the first comparison was false, the following code would run because the logical operator or would check both operands, and as long as one is true, would proceed.
In order to work around that, you would have to precisely state what it's comparing to, which is why you need to do it like so..
You could use tables in the following manner, to check for a match between your condition, and the values in table (table).
table = {'Condition1', 'Condition2'} if table[condition] or table[another] then --if condition is contained in -- table `table` -- work end -- or if v = random1 or v = random2 then
Yes, u can do it. Here's an example:
local2 = 0 local6 = 7 v = 0 if v == local2 or local6 then print ("Ok") end
either you assign v
as 0 or 7, "ok" will be printed