generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Functions in a Table

Previous Thread :: Next Thread 
Evorsor is not online. 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
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
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 is not online. 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 is not online. 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
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
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
GnomeHarrison is not online. GnomeHarrison
Joined: 26 Oct 2012
Total Posts: 149
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
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
03 Jan 2013 08:00 AM
Looks more complicated to me. I'm used to being dirty I guess.
Report Abuse
GnomeHarrison is not online. GnomeHarrison
Joined: 26 Oct 2012
Total Posts: 149
03 Jan 2013 08:01 AM
oooooo
robertoooo
Report Abuse
1Topcop is not online. 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
FreeToTake is not online. FreeToTake
Joined: 21 Apr 2010
Total Posts: 1827
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 is not online. 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 is not online. 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 is not online. 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
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
03 Jan 2013 08:15 AM
Too complicated for what this forum was asking for, lol. Nice scripting though.
Report Abuse
jobro13 is not online. 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
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
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 is not online. 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 is not online. 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 is not online. Luc599345
Joined: 25 Jul 2008
Total Posts: 1169
03 Jan 2013 09:02 AM
"Game.String.rev"

Wut?
Report Abuse
Luc599345 is not online. 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 is not online. 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
marioblox1094 is not online. marioblox1094
Joined: 14 Aug 2010
Total Posts: 1839
03 Jan 2013 09:04 AM
He didn't overwrite it. He capitalized it.
Report Abuse
1Topcop is not online. 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
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
03 Jan 2013 09:06 AM
Mario, both game.Lighting and Game.Lighting will get you to the same place.
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
03 Jan 2013 09:07 AM
Lol I give up, top always answers the same answer before I get to it... zzz
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image