This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Doyle3694's profile picture

Using tabled functions

Started by Doyle3694, 26 September 2012 - 07:31 PM
Doyle3694 #1
Posted 26 September 2012 - 09:31 PM
I want to use the functions I located in my table. How do I do that?
GopherAtl #2
Posted 26 September 2012 - 09:42 PM
same as any other functions. ().


local function f1()
  print("Hello world!")
end

local function f2(name)
  print("Hello, "..name.."!")
end

local myFunctionTable= {
   f1=f1,
   f2=f2,
}

myFunctionTable.f1()
myFunctionTable.f2("bob")
Jan #3
Posted 26 September 2012 - 09:46 PM
The advantage is that you can also use a variable as index


key=read()
myFunctionTable[key]()
Doyle3694 #4
Posted 26 September 2012 - 09:47 PM
oh () at the end… derp, thanks :P/>/>