Hi, this is kinda of confusing to explain, but bear with me.
local Table = {
Var1 = false;
Var2 = false;
};
local function CheckTable(TableToCheck)
for i,v in pairs(TableToCheck) do
if v == false then
return i
end
end
end
local VariableThatsEqualToFalse1, VariableThatsEqualToFalse2 = CheckTable(Table)
print(VariableThatsEqualToFalse1, VariableThatsEqualToFalse2) -- Output: "Var1 nil"
I loop through the table and check if something is equal to false. In this case there are 2 things that are equal to false in my Table, that would be Var1 and Var2. in my function I returned i so I could see which Variables in the table was equal to false. It should have printed out “Var1 Var2” but it printed out “Var1 nil”. How would I get it to print out “Var1 Var2”? Or in other words how would I get the function to return all names of the variables that are equal to false?
local Table = {
Var1 = false;
Var2 = false;
};
local function CheckTable(TableToCheck)
for i,v in pairs(TableToCheck) do
if v == false then
return i
end
end
end
print(CheckTable(Table))
local Table = {
Var1 = false;
Var2 = false;
};
local function CheckTable(TableToCheck)
local Total = {}
for i,v in pairs(TableToCheck) do
if v == false then
table.insert(Total, i)
end
end
return Total
end
print(CheckTable(Table))
I’m on mobile so I’m pretty slow rn
I literally returned a table