check if all statements are false

Is there a way to execute a line of code only if multiple statements are false?

I have an inventory:

[code]inventory = {
{“Images/Category 1/pistol1.png”, false},
{“Images/Category 1/machinePistol1.png”, false},

{“Images/Category 2/shotgun1.png”, false},
{“Images/Category 2/assaultRifle1.png”, false},

{“Images/Category 3/sniperRifle1.png”, false},
{“Images/Category 3/rocketLauncher1.png”, false}
}[/code]

And I’d like to write a function that executes a line of code if all those statements are false. [import]uid: 200198 topic_id: 35037 reply_id: 335037[/import]

Manage to solve it, wasn’t aware that the “and” operator worked for if statements (was trying to use &, &&, ||, etc)

if (inventory[1][2] == false and inventory[2][2] == false and inventory[3][2] == false and inventory[4][2] == false and inventory[5][2] == false and inventory[6][2] == false) then warningText.isVisible = true else showInven() end [import]uid: 200198 topic_id: 35037 reply_id: 139310[/import]

[lua]local function checkAllPolarVal( tbl, polar )
for i=1, #tbl do
if (tbl[i][2] ~= polar) then
return false
end
end
return true
end

if (checkAllPolarVal( tbl, false )) then print(“All false”) end[/lua] [import]uid: 8271 topic_id: 35037 reply_id: 139315[/import]

Or you could even make the check for a particular value in a function:

[lua]-- checks for a particular function, like a sort() compare function
local function retrieveValue( item )
return item[2]
end

– searches a table for values which do not match the required value
– calls the “get value” function to inspect the table entries
local function checkAllForValue( tbl, getValueFunc, val )
for i=1, #tbl do
if (getValueFunc( tbl[i] ) ~= val) then
return false
end
end
return true
end

– the value to search for
local checkFor = true

– do search
if (checkAllForValue( tbl, retrieveValue, checkFor )) then
print("All "…tostring(checkFor))
else
print("Not All "…tostring(checkFor))
end[/lua] [import]uid: 8271 topic_id: 35037 reply_id: 139323[/import]

Manage to solve it, wasn’t aware that the “and” operator worked for if statements (was trying to use &, &&, ||, etc)

if (inventory[1][2] == false and inventory[2][2] == false and inventory[3][2] == false and inventory[4][2] == false and inventory[5][2] == false and inventory[6][2] == false) then warningText.isVisible = true else showInven() end [import]uid: 200198 topic_id: 35037 reply_id: 139310[/import]

[lua]local function checkAllPolarVal( tbl, polar )
for i=1, #tbl do
if (tbl[i][2] ~= polar) then
return false
end
end
return true
end

if (checkAllPolarVal( tbl, false )) then print(“All false”) end[/lua] [import]uid: 8271 topic_id: 35037 reply_id: 139315[/import]

Or you could even make the check for a particular value in a function:

[lua]-- checks for a particular function, like a sort() compare function
local function retrieveValue( item )
return item[2]
end

– searches a table for values which do not match the required value
– calls the “get value” function to inspect the table entries
local function checkAllForValue( tbl, getValueFunc, val )
for i=1, #tbl do
if (getValueFunc( tbl[i] ) ~= val) then
return false
end
end
return true
end

– the value to search for
local checkFor = true

– do search
if (checkAllForValue( tbl, retrieveValue, checkFor )) then
print("All "…tostring(checkFor))
else
print("Not All "…tostring(checkFor))
end[/lua] [import]uid: 8271 topic_id: 35037 reply_id: 139323[/import]