title: Is it possible to store data next to an userdata chunk from inside lua?
body: <p>I'm making a mod for a game called Scrap Mechanic and was trying to get parts to easily communicate with one another. Usually this would mean creating a global table, filling that global table with variables I want to communicate and then retrieve them from the other part using the id of the part that stored it. Problem with this is that its bulky and I was wondering if there was an easy way to get this to work. The games lua API looks a bit like this:</p>
  
  <pre class="lang-lua prettyprint-override"><code>self = {interactable = {&lt;interactable&gt;, id = 1}, shape = {&lt;shape&gt;, id = 1}}
  </code></pre>
  
  <p>There are more of these, but the main part is that these contain the API's main functions. I can swap between the 2 using functions, get data from the game and set variables like the block's output (unfortunately I can only set 1 variable and 1 boolean which makes transferring large amounts difficult).
  The issue I am running into with this is that when I try to store a value in self.interactable or self.shape it gets changed for every object in the game to that value, instead of just putting it next to the userdata/metatable (still not sure which of the 2 it is so help with that would also be great).</p>
  
  <p>Now I have tried to use insertraw or whatever it is as well as other functions involved with metatables to ignore the __newindex function that might be in the table, but I can't access that part of the library and there seam to be no other answers on the web to this. I also tought of maybe retrieving the self portion from self.interactable, but I only have acces to interactable and (at least not in the games API) no way to go back from interactable to self, but thats not the question here, although an answer to this would help a lot because I can actually store data in self without interfering with other parts.</p>
  
  <pre class="lang-lua prettyprint-override"><code>function test1.server_onFixedUpdate( self, dt ) --code for one of the parts
      self.interactable.testValue = 1
  end
  
  function test2.server_onFixedUpdate( self, dt ) --code for another part
      print(self.interactable:getSingleParent().testValue) --returns the interactable of the connected part and accesses testValue
      print(self.interactable.testValue)
  end
  </code></pre>
  
  <p>When doing this you would expect the output to read <code>1, nil</code> but instead it reads <code>1, 1</code> which suggests that testValue has been placed in both parts. When printing self.interactable it only prints <code>{&lt;interactable&gt;, id = 1}</code> which leads me to think it stored the value inside the metatable that is default for every part. And using <code>insertraw( self.interactable, testValue, 1 )</code> just gives me back an unknown global error (if I used the wrong function here, dont worry, I typed it correct in the code).</p>