title: Lua 5.2.1 - Edit and save variable in file
body: <p>I have a file which is part of a game I'm making, and I am trying to manipulate it with code.</p>
  
  <p>Here is the file:</p>
  
  <pre><code>tech = 
  {
      weaponstech = 1.5,
      armortech = 1.8,
      shieldstech = 2 
  }
  </code></pre>
  
  <p>I am trying to open the file like this</p>
  
  <pre><code>local file = io.open("tech")
  </code></pre>
  
  <p>and then try to change the value of the variable 'shieldstech' to 2.2.</p>
  
  <p>I need this to happen automatically every time I run a function.</p>
  
  <p>I usually use single variable files such as this:</p>
  
  <pre><code>v = 1
  </code></pre>
  
  <p>but that just gives me a clutter of files which is unmanageable. </p>
  
  <p>so now I store variables the way I wrote my tech file.</p>
  
  <p>This is how I used to edit these single-variable files:</p>
  
  <pre><code>local file = io.open("file", "w")
  file:write("v = "..var)
  file.close()
  </code></pre>
  
  <p>but it is just too much work to rewrite the whole file in a single line or code, so I want to just change and save the variable, something like this:</p>
  
  <pre><code>local file = io.open("tech", "w")
  shieldstech = 2.2
  file:close()
  </code></pre>
  
  <p>but it won't work like that, and I know why. I'm not telling the program to edit the file, I'm telling it to edit the variable in that instance of the program. All I'm doing to the file is opening it and then closing it.</p>
  
  <p>Any of you guys know a way to do this?</p>
  
  <p>Thx, </p>
  
  <ul>
  <li>Brendan</li>
  </ul>