Hey there! I have a question, I am currently writing a ProccessReceipt where it needs to loop thru a table of ProductId’s, and if the ProductId corrosponds to one of the ProductId’s in the table, it needs to do something.
Now my question is, how would I make that happen, I tried this so far:
for i, v in pairs(donoIDS) do
if receiptInfo.ProductId == donoIDS then
but that doesnt seem to work, does anyone have any solution to this? Thanks!
You’re essentially checking if a number (ProductID) is equal to a table. You’d probably want to check if it is equal to either the index or the value. If you have a map with the ProductId as the key you can simply check if the ProductId exists (ex. if (donoIDS[receiptInfo.ProductId] ~= nil) then), if you have it in the value or something then you would be correct in thinking you have to search through the table, just make sure you check in the right place. For example using the ProductId as a key:
local donoIDS = {
[0] = {["Action"] = "Do something"},
[1] = {["Action"] = "Do something else"}
}
function GetProductInfo(id)
if (donoIDS[id] ~= nil) then
return donoIDS[id];
else
-- Does not exist.
return false;
end
end
print(GetProducInfo(1)["Action"]) -- Will print "Do something else".