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

{<These}

Started by deprilula28, 13 January 2015 - 09:13 PM
deprilula28 #1
Posted 13 January 2015 - 10:13 PM
I'm such a noob at cc…
I really don't have a less of idea of how {these} work.
What I wanna do is pick up this:

{
{
capacity = 10000
contents = {
rawName = Water
amount= 1000
name = Water
id = 1
},
},
}
and then pick rawName, amount and name to put them into local variables, like that:


local rawName = " "
local amount = 0
local name = " "

tank = peripheral.wrap("back")
<Anything that could pick tank.getTankInfo() and pick up rawName, amount and name>
…please
Bomb Bloke #2
Posted 13 January 2015 - 10:31 PM
http://lua-users.org/wiki/TablesTutorial

http://www.computercraft.info/forums2/index.php?/topic/19709-table-help/
deprilula28 #3
Posted 13 January 2015 - 10:47 PM

ok now I see how these tables are hard…
I'll leave my time understanding how these work..
but thank you!
KingofGamesYami #4
Posted 13 January 2015 - 10:47 PM

local t = {
  {
     capacity = 10000,
     contents = {
        rawName = Water,
        amount= 1000,
        name = Water,
        id = 1,
     },
  },
}
--#Here's one way
local rawName = t[1].contents.rawName
local amount = t[1].contents.amount
local name = t[1].contents.name
local capacity = t[1].capacity
--#Here's another
local rawName = t[1]["contents"]["rawName"]
local capacity = t[1]["capacity"]
--#this won't work..
local rawNAme = t.1.contents.rawName
--#..because 1 isn't a string.

Hopefully this helps. Tables are the most helpful thing in lua, learning them will help you a lot.

Edit: Added more examples and commas.
Edited on 13 January 2015 - 09:56 PM
deprilula28 #5
Posted 18 May 2015 - 02:29 AM

local t = {
  {
	 capacity = 10000,
	 contents = {
		rawName = Water,
		amount= 1000,
		name = Water,
		id = 1,
	 },
  },
}
--#Here's one way
local rawName = t[1].contents.rawName
local amount = t[1].contents.amount
local name = t[1].contents.name
local capacity = t[1].capacity
--#Here's another
local rawName = t[1]["contents"]["rawName"]
local capacity = t[1]["capacity"]
--#this won't work..
local rawNAme = t.1.contents.rawName
--#..because 1 isn't a string.

Hopefully this helps. Tables are the most helpful thing in lua, learning them will help you a lot.

Edit: Added more examples and commas.

Oh yeah, that helps a lot! Sorry for like 1 year to awnser… I should really check forums…

Edit:
You deserve it, so I gave you a green arrow thingy, and you explained it pretty easly!
I suck at programming so I probably I'm stuck with something horrible, but thank you a lot!
Edited on 18 May 2015 - 12:33 AM