dudeim
Member
- Joined
- Oct 5, 2007
- Messages
- 121
- Reaction score
- 9
Hey,
I want to know how to use tables inside tables.
Here is a script and I want to know if there is a correct way in there or I need to use another way
So is the function example or example2 correct? Or do I need another way to do this?
Thanks!
I want to know how to use tables inside tables.
Here is a script and I want to know if there is a correct way in there or I need to use another way
Lua:
ExampleTable = { Example1 = { Example2 } }
-- ok so now I can have something like: ExampleTable.Example1.Example2 right?
function example()
for i = 1,100 do
for j = 1,10 do
ExampleTable.Example1[i].Example2[j] = i+j --this line is this possible or do I need to set it up otherwise/use table.insert first?
end
end
function example2()
for i = 1,100 do
for j = 1,10 do
if ExampleTable.Example1[i].Example2[j] == nil then -- so this checks if the value exists and if it doesn't it inserts the value in the appropiate key and if it already exists then it just changes the value to the new value
table.insert(ExampleTable.Example1[i].Example2[j],i+j)
else
ExampleTable.Example1[i].Example2[j] = i+j
end
end
end
Thanks!