create a number of tables

How would I make a sensitive number of tables in a function, this code gives me:

ERROR: Failed to execute new( params ) function on ‘test’.
…Users/calebplace/Desktop/CoronaProjects/MyProject/main.lua:179: attempt to index global ‘myTable’ (a nil value)

[lua]local function makeSomeTables(params)
local numTables=#params
for i=1, numTables do
myTable[i]={}
end
end[/lua]

What that should do is create a table for each member in the ‘params’ table. But it has that error above. What should I do? [import]uid: 147322 topic_id: 28941 reply_id: 328941[/import]

You are getting the error because to Corona, myTable is a simple variable not a table:

-- this will tell Corona that myTable should be a table and make it available to this module  
--  
local myTable = {}  
  
local function makeSomeTables(params)  
 local numTables=#params  
 for i=1, numTables do  
 myTable[i]={}  
 end  
end  

[import]uid: 19626 topic_id: 28941 reply_id: 116557[/import]

Create myTable as a table before you enter the loop. For example:

[lua]local function makeSomeTables(params)
local myTable = {};
local numTables=#params
for i=1, numTables do
myTable[i]={}
end
end[/lua]

This way myTable is being read as a table and not being converted into a variable with one parameter such as an integer or boolean. [import]uid: 50511 topic_id: 28941 reply_id: 116563[/import]

Oops! I didn’t see @robmiracle’s post before mine! [import]uid: 50511 topic_id: 28941 reply_id: 116564[/import]

Thanks RoyMan and robmiracle! [import]uid: 147322 topic_id: 28941 reply_id: 116574[/import]