local Ups = { Body = { {"Still", {"Still1",15,100,false,"Its a still part", {DrainR = 1,Part = 2}}, . . . }
Im trying to script a tech system by using a lot of tables. I usually iterate through them multiple times like
for j,l in pairs(Ups) do for k,v in pairs(Ups[j]) do . . . --And so on. Its basically Inception...
It works fine (Maybe its inefficient, i wanted to avoid making scripts for each invidual button and manually placing the buttons) but i have a problem where i have to get the 'Body' from the table, but its not actually a member so i cant figure out how. Basicly what i want is for print(Ups[ j or 1]) to return "Body". Because i have a seperate table for the amounts of parts the player has on what they're building and what the limit for parts is. (Im using the same table for both Tech System and Building System)
local roverlimit = { Wheels = 0,Internal = 0,External = 0,Body= 1} local roveramount = { Wheels = 0,Internal = 0,External = 0,Body = 0}
I need to get the Ups[j] so i can look at what they are in roverlimit and roveramount. So i can do roverlimit[Ups[j]]
I think you're misunderstanding what the return variables from pairs
and ipairs
are.
In your code, l == Ups[j]
l
is the Value, j
is the Key. Since your key is the string, "Body", j
holds the string "Body" for the first iteration of the outer loop.
local Table = { Test = {yoloswag = "lol"}; Test2 = {See = "This is how they work.", Its = "moreValues lol"}; } for j, l in pairs(Table) do print("Searching sub-table " .. j) for k, v in pairs(l) do print(k .. " = " .. v) end end