Returning a value from a table, inside a table?

Unsure if that’s the proper terminology, but what I intended it to mean is much like what Gmod uses to handle Swep structure. For example you could return a specific value inside a specific table, inside that table by iterating through it and checking a common value shared between all tables inside that table. But my goal is to use it globally, and use that structure as a form of storing common variables. Everything I’ve tried to return only comes up dry, strangely, I did PrintTable and the values do show up in the log. So I know they exist, but they aren’t read. So after a lot of debugging I’m still unsure as to how this can work. Am I doing something wrong?

Do you have a sample? Hard to understand exactly what you mean.

for k,v in pairs( weapons.GetList()[ 1 ] ) do
print( k )
end

This is pasted straight from the deprecated wiki, I’m only using this as an example because it portrays the kind of variable system I’d like to use. Basically it’s iterating through a large table, in this case, weapons loaded into the current game. You can use your logic with common variables stored inside of each table. Like for example in that bit of code, you could return values from weapon-unique variables and it would be able to compare those values between all of them, because they all use the same variables, with different values, essentially filtering results.

I don’t know if I’m getting you. You want to loop through a table and compare that table’s values with another table’s values?

Not exactly, all the comparing is done inside the table, inside the table being iterated. The only purpose of the iteration is to compare values between all of the tables.

If you have a table inside a table like this.



varTable = {}
varTable[1] = {newVar = "testVar"}
varTable[1][1] = {compareVar = "testVar"}

if varTable[1].newVar == varTable[1][1].compareVar then
          --Do somthing.
end


With out code example all we can do is show example of tables inside of tables.
Another example on how you can do it is.



varTable = {}
compareTable = {}
compareTable[1] = {compareVar = "testVar"}
varTable[1] = {newVar = "testVar", compare = compareTable}

if varTable[1].newVar == varTable[1].compare[1].compareVar then
          --Do Somthing
end


if these are not what what your looking for show us an example of how you have tried.

Have you heard about 2d tables? Like Vissaben said.

[LUA]myTable = {}
myTable[1] = {Author = “Me”, Version = “1.0.0”}
myTable[2] = {Author = “You”, Version = “2.0.0”}

for k, v in ipairs(myTable) do
print(v.Author) // It will print the 2 Author because we have 2 table inside myTable
print(v.Version) // It will print the 2 Version because we have 2 table inside myTable
end[/LUA]

if I did something wrong then use this method

[LUA]for k, v in ipairs(myTable) do
print(v[“Author”]) // It will print the 2 Author because we have 2 table inside myTable
print(v[“Version”]) // It will print the 2 Version because we have 2 table inside myTable
end[/LUA]

I am using these kind of tables for SQL. To query a whole row.