problems with the length of a table

Hello, someone can explain me why?.

local vector={“bas”,500,“esp”,math.random(1,3),“mob”,nil,“abajo”,nil,“pis”,nil,“mob”,nil,“normal”,nil,“dip”,nil,“cer”,“esp”}

print (“longitud”, #vector)

print in screen 18 (is OK). but

local vector={“bas”,500,“esp”,math.random(1,3),“mob”,nil,“abajo”,nil,“pis”,nil,“mob”,nil,“normal”,nil,“dip”,nil,“cer”,“esp”,1}

print (“longitud”, #vector)

print in screen 7 (why?). 

Why not calculate the length right?

Thank you

operator does not give length it gives the number of successive integer indexes and is very inconsistent as you see. It work fine if you have no nil values in your table. When it finds nil it usually stops. What you want is table.maxn(vector).

operator does not give length it gives the number of successive integer indexes and is very inconsistent as you see. It work fine if you have no nil values in your table. When it finds nil it usually stops. What you want is table.maxn(vector).