|
| 06 Oct 2013 12:44 PM |
local newName = { b1Down = false, ammoInClip = 0, maxInClip = 0, ammoOutClip = 0, lastEventType = nil, }
Why does print(#newName) return 0? Also the for n,v in pairs(newName do doesn't seem to be working. Any ideas? |
|
|
| Report Abuse |
|
|
lucas668
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 6183 |
|
|
| 06 Oct 2013 12:59 PM |
print(#newName) will return 0 because there are 0 numbered indices - Example
tab = {false, 0, 0, 0, nil} print(#tab)
will return 4 (nil doesn't count because its nil and considered empty) because the indices for those items are created by their order in the table and aren't represented by a string or object index (By the way, 'index' plural is 'indices'). You indexed your values as strings instead of numbers so they are not counted ("b1Down" is the string index for "false", example newName["b1Down"] and newName.b1Down are accessing the same value, but newName[1] would be nil).
pairs(newName) would work, although ipairs(newName) would not. iPairs goes through numbered indices and ignores strings, pairs does not. |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2013 01:08 PM |
function tLen(tab) local x=0; for i,v in pairs(tab)do x=x+1; end return x; end
print(tLen(newName)); |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2013 01:18 PM |
local tbl = { primary = nil, secondary = nil, }
for n,v in pairs(tbl) do print(n,v) end
this prints nothing :( |
|
|
| Report Abuse |
|
|
| |
|
| |
|