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.



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

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


[Please log in to post a comment]