I am trying to compare two tables of equal length with a function, since I do not know another way to do this. However, with the following function, it does not register, and I do not know why. I hope someone can clarify this problem or better compare these two tables.
The tables are populated with the following code:
str = "parameters determined by program (all digits)"
tableone = {}
for word in str:gmatch("%d") do table.insert(tableone,word) end
It is identical for both tables, except, of course, for the names of individual tables. Tables are filled in correctly and displayed correctly when I print them. Here are two tables for this question:
tableone = {}
tabletwo = {}
for i=1,4 do table.insert(tableone, i) end
for i=1,4 do table.insert(tabletwo, i) end
Obviously, these two tables will be equal to each other. The function I wrote to compare index tables is as follows:
function comparetables(t1, t2)
matchct = 0
for i=1,
if t1[i] == t2[i] then
matchct = matchct + 1
end
if matchct ==
return true
end
end
I tried to do
print(comparetables(tableone,tabletwo))
, "true", . , , . . ? - table.compare, -, , , . !
:
mastermaind. , . , , , , .
- , , Ccount 1.
- , , Pcount 1
, {1, 3, 3, 4} {4, 4, 3, 1} Pcount 2 ( 4 1) Ccount 1 ( ). , , , 4 Pcount .