TB.TEST_Count()

In Hollywood there is a native function that returns how many items are stored into a table, it is ListItem(), however this function works only with tables indexed by numeric (and consecutive) values, starting from 0.

The TB.Count() function is able to count every table, even the ones with strings as index.

  Local items = { [0] = 43, 
                  [1] = 49, 
                  [4] = 192, 
                  music = "test.mp3" }  

  NPrint("TB.COUNT  : ", TB.Count(items))
  NPrint("ListItems : ", ListItems(items))
  
  NPrint("\nENTER TO QUIT")
  InKeyStr(#ALL)

As you can see items are counted correctly using TB.Count(), even with mixed index types, while ListItems() stops at the first NIL index starting from 0.

hollywoodlibs/tables/testcount.txt · Ultima modifica: 2016/10/16 12:03 da admin
CC Attribution-Noncommercial 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0