How To Detect Which Statement Is False?

Hello, I would deeply appreciate any help.

  1. What do you want to achieve? Keep it simple and clear!
    I want to use one if statement and detect which one is false
  2. What is the issue? Include screenshots / videos if possible!
    I don’t know how to do it, for example:
if "statement1" == true and "statement2" == true then
print("all statements are true")
else
print("the false statement") --prints which false statement
end
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    None.

umm

local statement1 = true
local statement2 = false

if statement1 == true and statement2 == true then
print("Both of these statements are true!")
end
if statement1 == false then
print(statement1.. "is false")
end
if statement2 == false then
print(statement2.."is false")
end
1 Like
local statement1 = nil --change
local statement2 = nil --change

if statement1 == true and statement2 == true then
	print("Both true!")
elseif statement1 == true and statement2 == false then
	print("1 is true, 2 is false")
elseif statement1 == false and statement2 == true then
	print("1 is false, 2 is true")
elseif statement1 == false and statement2 == false then
	print("Both false!")
end
1 Like

but I want to use only one if statement, and no elseif

From my understanding of the question, one of the statements must be true and the other false otherwise it would be impossible to do with one if statement and no elseifs.
In which case:

if statement1 == true then
    print("statement1 is true")
else
    print("statement2 is true")
end
1 Like

Ok, thanks for replying
I meant if There were three if statements:

if statement1 == true and statement2 == true and statement3 == true then
-- all statements are true
else
print("the false statement") -- prints which false statement has to be one of the three
end
local statements = {["s1"] = false, ["s2"] = true, ["s3"] = true}

if statements["s1"] == true and statements["s2"] == true and statements["s3"] == true then
	print("All true!")
else
	for sName, sValue in pairs(statements) do
		if sValue == false then
			print(sName.." is false!") --s1 is false!
		end
	end
end

A table value would be the way to go.

1 Like

Thank you so much!
(And to all you helped)