Variable use in table.maxn and similar functions

How does one use variables in standard table.maxn or similar functions?

I for example have a table called “maps”:

  • local maps
  • {
  • “map_a”,
  • “map_b”,
  • }

I do then retrieve an element at random (at index 1 in the example) from the table “maps” and save it in a variable called “currentmap”:

  • local currentmap = table.concat(maps, “”,1, 1 )

I have two more tables, one for each map:

  • local map_a
  • {
  •   “positon_aa”,
  •   “positon_ab”,
  • }
  • local map_b
  • {
  •   “positon_ba”,
  •   “positon_bb”,
  • }

Finally i want to calculate the number of elements in the table using table.maxn in combination with the “currentmap”-variable and save it in another variable called “positions” for further computations:

  • local positions = table.maxn(currentmap)

When compiling it shows an error and says table.maxn is met with a string where a table was expected.

The problem is that my first table “maps” is containing strings, but these strings are also the name of a table.

How would i go about telling the programm to look for the string as a tablename or insert the elements as variables into the “maps”-table if that makes any sense?

When answering please keep in mind that this was just a simplified example.

If at all possible i need to “automate” the table.maxn and/or table.concat commands to the point where i don’t have to hardcode every possibility.

Thanks in advance

Cashdong

You’re missing the ‘=’ character when defining your tables. They should look like this:

local maps = { "map\_a", "map\_b", }

You’re missing the ‘=’ character when defining your tables. They should look like this:

local maps = { "map\_a", "map\_b", }