Author Topic: more problems with tables...  (Read 1844 times)

0 Members and 1 Guest are viewing this topic.

Offline st0ne-db

  • Scripter
  • Double Ace
  • ******
  • Posts: 107
  • Karma: +14/-3
more problems with tables...
« on: 30 October, 2005, 05:16:57 »
ok... here is an example of what im trying to do:

Code: [Select]

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

PtokaX forum

more problems with tables...
« on: 30 October, 2005, 05:16:57 »

Offline Corayzon

  • Lord
  • ***
  • Posts: 464
  • Karma: +1/-0
(No subject)
« Reply #1 on: 30 October, 2005, 08:55:55 »
MyTable = { }

local TableName = "MyTable"

MyTable[TableName] = {[0] = "test1", [1] = "test2"}

Offline Corayzon

  • Lord
  • ***
  • Posts: 464
  • Karma: +1/-0
(No subject)
« Reply #2 on: 30 October, 2005, 09:05:34 »
Quote
Originally posted by st0ne-db
ok... here is an example of what im trying to do:

Code: [Select]

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:

Code: [Select]

tMyTable = { }

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

table.insert(tMyTable, tTableToInsert)


Offline st0ne-db

  • Scripter
  • Double Ace
  • ******
  • Posts: 107
  • Karma: +14/-3
(No subject)
« Reply #3 on: 30 October, 2005, 09:16:27 »
thanks so much for the great explanation... after using your suggestion everything works.  thx again.

PtokaX forum

(No subject)
« Reply #3 on: 30 October, 2005, 09:16:27 »