I am trying using the for _ in pairs()
notation to iterate over a table within a function, but if I type anything, even gibberish like print('asdgfafs')
, nested inside the for loop, it never gets printed. Code:
record = {bid1,bid2,bid3}
bid1 = {bidTime = 0.05,bidType = 'native'}
bid2 = {bidTime = 0.1,bidType = 'notNative'}
bid3 = {bidTime = 0.3,bidType = 'native'}
function getBids(rec,bidTimeStart,bidTimeFinish,bidType,numberOfBids)
wantedBids = {}
bidCount = 0
for i,v in pairs(rec) do
print('asdfasdfasdfa')
print(i .. ' + ' .. v)
end
end
getBids(record,0,1,'native',5)
Can anyone tell me why and suggest a workaround?
You are creating the
record
table before creating thebid#
tables.So when you do
record = {bid1, bid2, bid3}
none of thebid#
variables have been created yet and so they are allnil
. So that line is effectivelyrecord = {nil, nil, nil}
which, obviously, doesn't give therecord
table any values.Invert those lines to put the
record
assignment after thebid#
variable creation.