local list =
{
[1] = function ()
print("A")
print("B")
print("C")
print("D")
end,
[2] = function ()
end
}
if type(list[1]) == "function" then
list[1]()
end
I want to print ABCDE if I choose key [1]
LUA:local testB = { [1] = { {print("A")}, {print("B")}, {print("C")}, {print("D")}, {print("E")} }, [2] = { } } testB[1]
testTable = {
[1] = "ABCDE"
}
function testFunc(value)
if testTable[value] then
print(testTable[value])
end
end
print(testTable[1])
testFunc(1)
local testTable = {
[1] = {function() print("A") end, function() print("B") end}
}
testTable[1][1]() -- prints A
-- to print all:
for i = 1, #testTable do
for j = 1, #testTable[i] do
testTable[i][j]()
end
end
local t = {blablabla = function(x, y, z) return x, y, z end}
print(t.blablabla(3,4,5))
it got executed because you're calling print directly, not placing a value into the table. print returns nil so your table was filled with 5 nil values
if one of us solved your problem you can click the "best answer" button on the post next to the buttons on the bottom right
local table = {
"A", "B", "C", "D" }
for s = 1, #table do
print(table[s])
end
For example:
LUA:local table = { "A", "B", "C", "D" } for s = 0, #table do print(table[s]) end
when you call a function, you get a value returned back after it's executedbut print["A"] was in a table
function myFunc()
return 5
end
local sometable = {
myFunc(),
myFunc(),
myFunc()
} -- {5, 5, 5}
local othertable = {
function() return myFunc() end,
function() return myFunc(), end,
function() return myFunc() end
} -- {function, function, function}
print(sometable[1]) -- prints 5
print(othertable[1]) -- prints function: (memory address the function is stored at)
print(othertable[1]()) -- prints 5, since othertable[1] is a function waiting for execution