你可以使用一个变量,并假设它是真的
local IsEverythingTrue = true
-- the **for** statement is a loop. It will allow us to operate
-- the same way on any number elements in inventory.
-- _,v stands for variables that we are going to read from inventory table
-- we can't do it directly, however; **ipairs** function will prepare it so
-- _ will hold numerical index of each element (1, 2, 3 and so on);
-- we don't use it, though, so I put in a placeholder name
-- v will hold every value, so your two-element table
for _,v in ipairs(inventory) do
-- if any value of v[2] is false, break
-- v[2] is equal to inventory[_][2]
-- if not v[2] can be written as
-- *if value of v[2] isn't true*
if not v[2] then
-- in this case, after first non-true element has been found
-- we know that not every one is true, or there is at least one false
IsEverythingTrue = false
break -- we don't have to check anything else
end
end
然后在表达式中使用该变量
if IsEverythingTrue then
-- do something
else
-- do something else
end
如果您希望它以多个错误执行,只需计算它们。local falseCount = 0
在开头添加,并更改break
为falseCount = falseCount + 1
.