From what I've noticed it seems like when you use/call the routine (table.remove) in a table your looping it stops the loop?.. If thats the case it causes some problem for me.
Here's a test I did:
tableTest = {
{ name = "test1" },
{ name = "test2" },
}
function test()
Note("tableTest1:")
for k, v in tableTest do
Note("k: " .. tostring(k) .. ". v.name: " .. tostring(v.name))
table.remove(tableTest, k)
end
Note("tableTest2:")
for ke, ve in tableTest do
Note("ke: " .. tostring(ke) .. ". ve.name: " .. tostring(ve.name))
end
end
Frist time I run function test.
It shows:
tableTest1:
k: 1. v.name: test1
tableTest2:
ke: 1. ve.name: test2
See, at tableTest1, it aborts the loop after the first table.remove. And then the second for loop, it shows that the table now only has the second value.
The real function I actually noticed this in, is alot bigger. And it call's another function and from there I remove the value from a table that's looping in the first function, and I would like to be able to remove any amount from 0 to 1000
Is there anyway to bypass this or maybe make an alternative way of doing this? (and also, the reason I loop the table is becuase im checking it with another, so I "have" to loop the table.)
Here's a test I did:
tableTest = {
{ name = "test1" },
{ name = "test2" },
}
function test()
Note("tableTest1:")
for k, v in tableTest do
Note("k: " .. tostring(k) .. ". v.name: " .. tostring(v.name))
table.remove(tableTest, k)
end
Note("tableTest2:")
for ke, ve in tableTest do
Note("ke: " .. tostring(ke) .. ". ve.name: " .. tostring(ve.name))
end
end
Frist time I run function test.
It shows:
tableTest1:
k: 1. v.name: test1
tableTest2:
ke: 1. ve.name: test2
See, at tableTest1, it aborts the loop after the first table.remove. And then the second for loop, it shows that the table now only has the second value.
The real function I actually noticed this in, is alot bigger. And it call's another function and from there I remove the value from a table that's looping in the first function, and I would like to be able to remove any amount from 0 to 1000
Is there anyway to bypass this or maybe make an alternative way of doing this? (and also, the reason I loop the table is becuase im checking it with another, so I "have" to loop the table.)