9 posts
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
7083 posts
Location
Tasmania (AU)
Posted 13 January 2015 - 10:31 PM
9 posts
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!
3057 posts
Location
United States of America
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
9 posts
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