corona - Lua search through table -
i working on game project using corona sdk , running issue. trying use string.find() in loop test determine if value in table , if so, add value table. problem since string.find()/string.match not read duplicates in case (assuming loop reason why). having "1102", "1103" instead of "1102", "1102", "1103", "1102", in "copy" table how trying do. suggestions?
database = { {name="test", serial="1102", img="src/1.png"}, {name="test2", serial="1103", img="src/2.png"}, {name="test3", serial="1104", img="src/3.png"} } list = { "1102", "1102", "1103", "1102" } copy = {} n=1 i=1, #database if string.find(database[i].serial, tostring(list[n])) table.insert(copy, database[i].img) n=n+1 end end i=1, #copy print(copy[i]) end
using nested loop works.
for lk, lv in ipairs(list) dk, dv in ipairs(database) if string.find(dv.serial, tostring(lv)) table.insert(copy, dv.img) end end end
i'm using ipairs
, similar for i=1, #list do
.
Comments
Post a Comment