This is more of a Lua question than LOVE. However, I am trying to compare tables, and have tried a few different ways, each with varying levels of success. End result, I want to check that table qa.entity.materials has all the required values of qa.ship.materials, but also if entity has the material[1] it also checks the second value in the table to make sure the amount in qa.entity.materials[2] is higher. I'll show you what I have here:
This is a hardcode version for testing, copy paste here to see what I mean.
Code: Select all
local qa = {ship = {}, entity = {}}
qa.ship.materials = {{10, 50}, {25, 100}, {95, 22}}
qa.entity.materials = {{10, 50}, {25, 100}, {95, 22}}
function qa.checkMaterials()
for i=1,#qa.ship.materials do
for _,v in pairs(qa.entity.materials) do
if qa.ship.materials[i][1] == v[1] then
if qa.ship.materials[i][2] > v[2] then
return false
else
print("Passed")
end
end
end
end
return true
end
if qa.checkMaterials() then print("All Clear") else print("Failed") end
Edit>> Forgot to mention, I did come up with a gritty way of doing it and that was by assigning another value to the array so it would not be nil, then looping through the list one more time, and returning false is any of the [3] were nil. But this way seems like the long way