title: Using variable to add key's to table
body: <p>I am trying to use a table and add new data(another table) to it by using the name of a variable as key, and adding that key to the table. My first approach was:</p>
  
  <pre><code>local table
  var = read()
  print(var.." "..type(var))
  table[var] = {name = var, foo = bar}
  </code></pre>
  
  <p>Unfortunally this causes an error(index expected, got nil). The print line in front of the table does print a value along with the type string if I enter a string value, yet it says it gets a nil in the line with the table. An bigger code snippet from the actual code(From the minecraft ComputerCraft mod):</p>
  
  <pre><code>m = peripheral.wrap("right")
  m.clear()
  m.setCursorPos(1,1)
  
  mline = 1
  
  bgcolor = colors.white
  txtcolor = colors.black
  
  debugbg = colors.green
  debugtxt = colors.lightGreen
  
  mainscreen = true
  searchscreen = false
  newitemscreen = false
  newitemconfirmation = false
  running = true
  
  recipes = {}
  temp_recipe = {}
   --end of variable declaration part, start of function declarations
  
  function write(text,x,y,cl,bg) --custom writing function
    term.setCursorPos(x,y)
    term.setBackgroundColor(bg)
    term.setTextColor(cl)
    term.write(text)
    term.setBackgroundColor(bgcolor)
    term.setTextColor(txtcolor)
  end
  
  ...
  
  function newItem()
    temp_recipe = {}
    write("Name of the item: ",1,3,txtcolor,bgcolor)
    local item = read()
    write("Amount of items: ",1,4,txtcolor,bgcolor)
    local itemAmount = read()
    write("Amount of items types needet for crafting: ",1,5,txtcolor,bgcolor)
    local ingredientCount = read()
    local ingredientList = {}
    for iC = 1,ingredientCount,1 do
      write("Name of crafting component "..iC..": ",1,6,txtcolor,bgcolor)
      ingredient = read()
      write("Amount of crafting component "..iC..": ",1,7,txtcolor,bgcolor)
     ingredientAmount = read()
     ingredientList[ingredient] = {name = ingredient, amount = ingredientAmount}
    end
  &gt;&gt;&gt;&gt;&gt;   temp_recipe[item] = {name = item, amount = itemAmount, ingredients = ingredientList} -- Line that causes the error
    term.setCursorPos(1,8)
    printRecipe(temp_recipe["name"],item) -- irrelevant function to display the entered data
  end
  </code></pre>
  
  <p>Is there a way to find a solution around this problem? The code is needet inside a function to assign multiple data entrys to the table, which then are accessible using the key representing the name.</p>