Autocomplete missing, help and tables [ANSWERED]

I am missing some functions in autocomplete, noTint(), no… etc, also in the references while using help, some buttons in “reference” section are not working…cant remember which one right now but it was in graphics section.

Then, the issue with tables is that i want to know how many elements have a table, do i need to iterate the whole table to know this value? …maxn just show me which number is the last used but not the current number of elements…i think this a basic in a programming language

Nice to write you :slight_smile:

Try the # operator on a table, it’s not documented, but seems to be a lua thing. Eg.

myTableLength = # myTable

Ah thanks for this, juaxix. I will have to add these to the autocomplete.

Unfortunately Lua has no built in way to find the total number of elements in a table. I was shocked when I discovered this, too. There are two solutions:

  1. iterate the whole table

  2. or create your own table that overrides __setindex, insert, and remove, and keeps a counter for the number of keys.

re. “#” - semi kinda. It’s documented (see below), but it shows you the “length”, which does not necessarily equal the total number of elements. To track that, you’d probably either iterate the table, or (assuming you’re the one adding and removing elements), just track it in a separate variable.

http://www.lua.org/manual/5.1/manual.html#2.5.7

2.5.5 - The Length Operator

The length operator is denoted by the unary operator #. The length of a string is its number of bytes (that is, the usual meaning of string length when each character is one byte).

The length of a table t is defined to be any integer index n such that t[n] is not nil and t[n+1] is nil; moreover, if t[1] is nil, n can be zero. For a regular array, with non-nil values from 1 to a given n, its length is exactly that n, the index of its last value. If the array has “holes” (that is, nil values between other non-nil values), then #t can be any of the indices that directly precedes a nil value (that is, it may consider any such nil value as the end of the array).

@Bortels, was just going to post that bit too - realised it would not work unless our table was full of stuff. Thanks!

Yeah #t is only for array style tables. It’s a little unfortunate there’s no such operator for arbitrary key-value style tables.

Wii! The “#” feature works :slight_smile: another thing learned today hahá!
In my case I used to store classes in tables, its reference are pointers, i guess…so…
Thanks!

There are more things i want to know but i forgot them right now xD