Log In  

It seems that calling count() changes the behavior of arrays:

    a = {}
    count(a)               --> calling count() here should NOT change anything
    a[1] = "hello"
    print( count(a) )  --> 0 .... NOT OK

While the same code without the initial call to count() works just fine

    a = {}
    a[1] = "hello" 
    print( count(a) )  --> 1 .... OK

Note that count() influence is countered if we use add() instead of implicit index:

    a = {}
    count(a)           
    add(a, "hello")
    print( count(a) )  --> 1 .... CORRECT

I got a really hard time finding the faulty behavior, as I obviously used count to check my array sanity... thought I was becoming crazy :)

Hope it helps.

P#13084 2015-08-24 16:59 ( Edited 2015-08-24 21:07)

The # operator for table works just find instead of count():

  a = {}
  a[1] = "hello" 
  print( #a )  --> 1 .... OK
P#13085 2015-08-24 17:06 ( Edited 2015-08-24 21:06)

[Please log in to post a comment]