|
| 16 Oct 2016 08:54 PM |
I have a fair knowledge on the understanding of tables, but however I have a question. It's regarding to dictionaries. So let's say that I iterate the table/dictionary with the for _,v in pairs loop. Can I count the amount of arrays in a dictionary?
I haven't really practiced that much with the use of dictionaries which I ought to.
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 16 Oct 2016 08:56 PM |
not directly. since dictionaries are indexed by keys, there is no length to them. You will have to manually add the keys.
local tab = { yo = 1, hi = 2, }
DictionaryLength = function(tab) local i = 0 for key in next, tab dp i = i + 1 end return i end
print(DictionaryLength(tab)) >> 2
|
|
|
| Report Abuse |
|
|
|
| 16 Oct 2016 08:57 PM |
Oh I see. That was helpful, thank you!
|
|
|
| Report Abuse |
|
|