PtokaX forum

Development Section => Your Developing Problems => Topic started by: st0ne-db on 30 October, 2005, 05:16:57

Title: more problems with tables...
Post by: st0ne-db on 30 October, 2005, 05:16:57
ok... here is an example of what im trying to do:


MyTable = { }

local TableName = "MyTable"
table.insert(TableName, { "test" } )


is there a way to convert a string variable to a type that can be called as a table.  because i keep getting this error:

attempt to index local 'TableName' (a string value)

 TIA    

-st0ne db
Title:
Post by: Corayzon on 30 October, 2005, 08:55:55
MyTable = { }

local TableName = "MyTable"

MyTable[TableName] = {[0] = "test1", [1] = "test2"}
Title:
Post by: Corayzon on 30 October, 2005, 09:05:34
QuoteOriginally posted by st0ne-db
ok... here is an example of what im trying to do:


MyTable = { }

local TableName = "MyTable"
table.insert(TableName, { "test" } )


is there a way to convert a string variable to a type that can be called as a table.  because i keep getting this error:

attempt to index local 'TableName' (a string value)

 TIA    

-st0ne db

I better mention why the above doesnt work:

Syntax for table.insert:

*** table.insert(Table, Variable)

Table is the table to insert Variable to
Variable is the variable to insert into Table

So your example should be:


tMyTable = { }

local tTableToInsert = {[0] = "test"}

table.insert(tMyTable, tTableToInsert)

Title:
Post by: st0ne-db on 30 October, 2005, 09:16:27
thanks so much for the great explanation... after using your suggestion everything works.  thx again.