Jump to content




Using tabled functions


  • You cannot reply to this topic
3 replies to this topic

#1 Doyle3694

  • Members
  • 815 posts

Posted 26 September 2012 - 08:31 PM

I want to use the functions I located in my table. How do I do that?

#2 GopherAtl

  • Members
  • 888 posts

Posted 26 September 2012 - 08: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")


#3 Jan

  • Members
  • 141 posts
  • Locationthe Netherlands

Posted 26 September 2012 - 08:46 PM

The advantage is that you can also use a variable as index

key=read()
myFunctionTable[key]()


#4 Doyle3694

  • Members
  • 815 posts

Posted 26 September 2012 - 08:47 PM

oh () at the end... derp, thanks :P/>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users