I am working on a game project using Corona SDK and I am running into an issue. I am trying to use string.find() in a for loop to test to determine if a value is in a certain table and if so, add that value to another table. My problem is that since string.find()/string.match does not read duplicates in this case (assuming that the for loop is the reason why). I am essentially only having "1102", "1103" instead of "1102", "1102", "1103", "1102", in the "copy" table which is how I am trying to get this to do. Any 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
for i=1, #database do
if string.find(database[i].serial, tostring(list[n])) then
table.insert(copy, database[i].img)
n=n+1
end
end
for i=1, #copy do
print(copy[i])
end
nintostring(list[n])? You want to match a value indatabaseif itsserialmatches any oflistor a specific one? What do the duplicate elements inlistmean? - Yu Haocopyto have one"src/1.png"and one"src/2.png", is this correct? - Yu Haosrc/1.png,src/1.png,src/3.png,src/1.pngwhich follows how 'list' is setup. - Terry Englishlisthas all of itsimgput intocopy- Terry English