Hello, so I am learning methods/functions in Tables which looks like this:
local table = {
[1] = {
["E"] = function()
print ('E pressed')
end,
}
}
And I am not sure on when to use it, can anyone give me ideas?
Hello, so I am learning methods/functions in Tables which looks like this:
local table = {
[1] = {
["E"] = function()
print ('E pressed')
end,
}
}
And I am not sure on when to use it, can anyone give me ideas?
I believe to use a function embedded inside of a table you would just call the position the function is in inside of the table.
Example:
local table = {
[1] = {
["E"] = function()
print('E pressed')
end,
}
}
table[1]["E"]() -- Should print "E pressed"
EDIT: And if you wanted to get a returned variable from the function you would just do this (again, I am pretty sure it works this way)
local value = table[1]["E"]()
print(value)
You would just need to add parentheses at the end of the indexed item.
table[1]["E"]()
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.