Fruits = { apple = { ordered = true, amount = 10 }}
i have several different kinds of fruits in this table and i need to output everything where ordered=true to make it look like this:
apple ordered: true | apple amount: 10
Made it like this
for a,b in pairs(Fruits) do
for c,d in pairs(b) do
if (d == true) then
print(a..” ordered: ”..tostring(d)..” | “..a..” amount: “..tostring(d)..”)
end
end
end
but the output is this
apple ordered: true | apple amount: true
The problem with your code is that you're looping over the "properties" of each fruit. Thus you have
c = "ordered"andd = trueinside the loop. Printingdtwice will lead to the output you have described. Here's the fixed code: