Accessing to elements - Table

Hi friends !!

I have a question about tables in Squirrel.

If there is a mistake please tell me, cause I’m a new Squirrel programmer :stuck_out_tongue:
Normally when creating a table we can make it like in the example bellow :

local table = {elem1 = 0, elem2 = 1, elem3 = 9};

and to access to an element(2nd for eg) we can do

table.elem2 = 66

My question is about accessing to an specific element using it’s range like table(2) to access to the 2nd element.
Is there any possibility to do that.

thanks a lot.


Sadly no: a table is, at heart, a collection of key/value pairs. The keys can be any value of Squirrel type (“elem2” is a string of course, 1 is an integer). So table.elem2 is the same thing as table[“elem2”], but isn’t the same thing as table[1].

You can access all the elements out of a table by using foreach, but (because tables are implemented internally using hash-tables) there are no guarantees about the order in which foreach accesses the elements.


[Edited to remove reply to a removed post]