This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
moomoomoo3O9's profile picture

Manipulating a value inside several nested tables

Started by moomoomoo3O9, 10 August 2014 - 10:05 PM
moomoomoo3O9 #1
Posted 11 August 2014 - 12:05 AM
Alright, so I'm loading a table containing NBT data for a block, which means it has to have the coordinates changed accordingly. Unfortunately, the table looks something like this:


Clipboard=
{[1]={["NBT"]={
type="compound",
value={
  id={type="string", value="Chest"},
  x={type="int", value=0},
  y={type="int", value=128},
  z={type="int", value=0},
  Items={
   type="list",
   value={
		{
		 type="compound",
		 value={
		  id={type="short", value=7},
		  Count={type="byte", value=64},
		  Damage={type="short", value=0},
		  Slot={type="byte", value=0}
		 }
		},
		{
		 type="compound",
		 value={
		  id={type="short", value=1},
		  Count={type="byte", value=32},
		  Damage={type="short", value=0},
		  Slot={type="byte", value=2}
		 }
		}
   }
  },
  randomLong={type="long", value={1, 2}},
  randomIntArray={type="intArray", value={1, 2, 3, 4}},
  randomByteArray={type="byteArray", value={5, 6, 7, 8}}
}
}
}
}

(If there are some curly braces missing, that isn't the problem, because I was modifying this table manually so it would look like the output of the program, as I can't test in-game at the moment)


Clipboard[1]["NBT"]["value"]["x"]["value"]=1
Clipboard[1]["NBT"]["value"]["y"]["value"]=2
Clipboard[1]["NBT"]["value"]["z"]["value"]=3

Any of those three lines will simply erase most of the table, leaving none of the other data. What should be done to fix that? How can one manipulate tables in such a way to make that work?
Edited on 11 August 2014 - 02:02 AM
Bomb Bloke #2
Posted 11 August 2014 - 08:17 PM
Those commands should only affect the specific variables within the tables that they reference - I suspect you're either misinterpreting the initial table state, or the results, or you're doing something else entirely to the table somewhere else in your code.

Otherwise you seem to have the right idea, but it's possible reading this will help you.
moomoomoo3O9 #3
Posted 12 August 2014 - 02:16 AM
That is unusual. I have no clue what caused that bug, but it is solved…

In a completely unrelated issue, I have no idea how NBT is supposed to work in Immibis Peripherals, but that is a question for Immibis, not anyone here.