Evorsor
|
  |
| Joined: 13 Aug 2012 |
| Total Posts: 212 |
|
|
| 03 Jan 2013 06:12 AM |
| Is is possible to put functions in a table? If so, how? |
|
|
| Report Abuse |
|
|
|
| 03 Jan 2013 06:53 AM |
| I believe you can use loadstring function, ans set your function as a string. That should work. |
|
|
| Report Abuse |
|
|
adark
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
|
| 03 Jan 2013 06:57 AM |
Or, you know, just put them in a table.
tab = {}
tab.Function1(num) num = num + num print(num) end
tab.Function1(12) --> 24 |
|
|
| Report Abuse |
|
|
adark
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
|
| 03 Jan 2013 06:58 AM |
Excuse me, tab.Function1 = function(num)
I haven't used Lua in a while. |
|
|
| Report Abuse |
|
|
|
| 03 Jan 2013 06:59 AM |
Variables...
MyTable={function1=function(a)print(a)end,function2=function()print("sup")end}
MyTable.function1("hello") MyTable.function2() |
|
|
| Report Abuse |
|
|
|
| 03 Jan 2013 07:55 AM |
@Robet Could that be cleaner, like:
MyTable={ function1 = function(a) print(a) end, function2 = function() print("sup") end }
? |
|
|
| Report Abuse |
|
|
|
| 03 Jan 2013 08:00 AM |
| Looks more complicated to me. I'm used to being dirty I guess. |
|
|
| Report Abuse |
|
|
| |
|
1Topcop
|
  |
| Joined: 09 Jun 2009 |
| Total Posts: 6635 |
|
|
| 03 Jan 2013 08:02 AM |
You could also use the "..." [Not operator, but what's the word I'm looking for?] in your print function, and be like,
MyStuff = { function1 = function(...) print(...) end ,function2 = function() print("Bleg") end }
MyStuff.function1(1,4,45) MyStuff.function2() |
|
|
| Report Abuse |
|
|
|
| 03 Jan 2013 08:03 AM |
_table = { ["print"] = function(t) for _,v in pairs(t) do print(tostring(v)) end end } _math = { ["round"] = function(v, d) return math.floor(v*d)/d end } _table.print({1, 5, 2, 6, true, "azrfaezpoifj", 123, false, _math.round(math.pi, 100))
would print
-> 1 -> 5 -> 2 -> 6 -> true -> azrfaezpoifj -> 123 -> false -> 3.14 |
|
|
| Report Abuse |
|
|
1Topcop
|
  |
| Joined: 09 Jun 2009 |
| Total Posts: 6635 |
|
|
| 03 Jan 2013 08:05 AM |
| Do it wouldn't, cause you forgot the end angle bracket. ;3 |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 03 Jan 2013 08:08 AM |
"Do it wouldn't" Wait what?! Dat grammar... |
|
|
| Report Abuse |
|
|
1Topcop
|
  |
| Joined: 09 Jun 2009 |
| Total Posts: 6635 |
|
|
| 03 Jan 2013 08:10 AM |
Why did I put "Do"? o.o I thought I hit the N. |
|
|
| Report Abuse |
|
|
|
| 03 Jan 2013 08:15 AM |
| Too complicated for what this forum was asking for, lol. Nice scripting though. |
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 03 Jan 2013 08:19 AM |
Uhm, yes...
local data = {} data.dump = function() for i,v in ipairs(data) do print(i..": "..v) end end
data.add = function(s) table.insert(data,s) end
data.add("Hi") data.add("Hello") data.add("Ok") data.dump()
1 Hi 2 Hello 3 Ok |
|
|
| Report Abuse |
|
|
|
| 03 Jan 2013 08:28 AM |
Actually:
1: Hi 2: Hello 3: Ok
Still a more complicated way of answering the original question... |
|
|
| Report Abuse |
|
|
1Topcop
|
  |
| Joined: 09 Jun 2009 |
| Total Posts: 6635 |
|
|
| 03 Jan 2013 08:37 AM |
You want a complicated way of answering the question? OK!
Game = { Gui = { new = function(par)return Instance.new(Game.String.rev("neercS","iuG"),par)end -- Since Game.String.rev returns the reversed string of all the strings first reversed, then concatenated, this will return Instance.new("ScreenGui",par) } String = {rev = function(...)local s = ""for n,o in pairs({...})do s=s..string.reverse(tostring(o))end return s end -- Har har c: } }
Game.Gui.new(game.Players[Game.String.rev(1,"poT","poc")].PlayerGui).Name = Game.String.rev("emosewA","ecuas") |
|
|
| Report Abuse |
|
|
1Topcop
|
  |
| Joined: 09 Jun 2009 |
| Total Posts: 6635 |
|
|
| 03 Jan 2013 08:41 AM |
| Well, I suppose that's more confusing then complicated. But it's certainly got more confusion then it should for adding a ScreenGui into my PlayerGui, and naming it Awesomesauce. |
|
|
| Report Abuse |
|
|
Luc599345
|
  |
| Joined: 25 Jul 2008 |
| Total Posts: 1169 |
|
| |
|
Luc599345
|
  |
| Joined: 25 Jul 2008 |
| Total Posts: 1169 |
|
|
| 03 Jan 2013 09:03 AM |
Oh, forget that, I didn't read the full script :\
It's still silly overwriting the Game variable, no? |
|
|
| Report Abuse |
|
|
1Topcop
|
  |
| Joined: 09 Jun 2009 |
| Total Posts: 6635 |
|
|
| 03 Jan 2013 09:04 AM |
| Well I never contact "game", as "Game", so I'll know that "Game" is my table of useless functions, and "game" is my game. |
|
|
| Report Abuse |
|
|
|
| 03 Jan 2013 09:04 AM |
| He didn't overwrite it. He capitalized it. |
|
|
| Report Abuse |
|
|
1Topcop
|
  |
| Joined: 09 Jun 2009 |
| Total Posts: 6635 |
|
|
| 03 Jan 2013 09:05 AM |
| Technically I did overwrite it, since DataModel can be contacted through either Game, or game, just like Workspace can be contacted as Workspace, workspace, or game.Workspace. |
|
|
| Report Abuse |
|
|
|
| 03 Jan 2013 09:06 AM |
| Mario, both game.Lighting and Game.Lighting will get you to the same place. |
|
|
| Report Abuse |
|
|
|
| 03 Jan 2013 09:07 AM |
| Lol I give up, top always answers the same answer before I get to it... zzz |
|
|
| Report Abuse |
|
|