2

Newbie Programmer I am using table within a table to store information on tabletop simulator using scripting

rpgPlayer = 123456 -- this is a string of values
masterTable.rpgPlayer = { test = "test1"} 
for n in pairs(masterTable) do 
    print(n) --- this comes out as rpgPlayer instead of 123456 
    end  

I used a cut down example of code but basically instead of creating a table within masterTable with the key = 123456 it creates a key = rpgPlayer is the way to point the program at value of rpgPlayer rather than the variable ?

1 Answers1

3

Use bracket syntax. tbl[var]

Dot syntax (tbl.var) uses string variable as value, this syntax is equivalent to tbl["var"].

You need to do this:

masterTable[rpgPlayer] = { test = "test1" }

Read more about table syntax: https://www.lua.org/pil/2.5.html

Spar
  • 1,582
  • 9
  • 16
  • @PluckyHero If it worked you can choose this answer as "accepted". [Read more what you should do when you found an answer](https://stackoverflow.com/help/someone-answers) – Spar Nov 23 '20 at 14:50
  • Sadly can't upvote and can't see the option to accept it. The upvoting seems to be because I literally created an account to ask this question and don't have enough reputation yet. I suspect I can't find the accept answer button due to the same reason? So all I can give is my genuine thanks and appreciation :). – Plucky Hero Nov 24 '20 at 11:13
  • @PluckyHero https://meta.stackoverflow.com/questions/251078/how-to-update-and-accept-answers – Spar Nov 24 '20 at 11:25