|
| 22 Jul 2013 11:40 PM |
local StringPat{
craft = Instance.new("Message",game.Workspace)
game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(msg) x = player.Name if msg == "string.rep" then craft.Text = ("User "..x.." has won the round, congratulations!") wait(6) craft.Text = ("The Round has Ended") craft.Parent = game.Lighting end end) end) }
Is this a proper way to put this whole piece of code in a table?
Plus, I was wondering if I had like a table full of other table names, how would I use math.random as to where it would randomly index one of the tables in the table. For instance:
TriviaRan{"StringPat","StringRev",StringChar"} -- Inside values are other tables that contain code like the one piece above. |
|
|
| Report Abuse |
|
|
Tuxwonder
|
  |
| Joined: 21 Jan 2008 |
| Total Posts: 888 |
|
|
| 22 Jul 2013 11:44 PM |
We need some help understanding what you're trying to do here
Are you trying to run this script inside of the table... somehow? |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2013 11:50 PM |
I want that large piece of code in a table. I'm going to make other pieces of code under different table names and of course different pieces of codes. I want all of the tables I create out of these pieces of code, to be in one table. So like if the first piece of codes name is StringPat and the next piece is StringRev.
I want to put these tables in one table and use math.random to randomize these tables inside to where when one of the tables gets picked, it runs that code. So if I randomize the table and I get StringPat I want it to run that piece of code.
It may be a bit complex to understand, I apologize for that. |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2013 11:58 PM |
local MasterTable = { {function() print"FirstCode" end}, {function() print"SecondCode" end}, {function() print"ThirdCode" end} }
They'd have to be functions.
function RunRandomCode() MasterTable[math.random(#MasterTable)][1]() --[1] since the function is inside of a table which is under the MasterTable end |
|
|
| Report Abuse |
|
|
Tuxwonder
|
  |
| Joined: 21 Jan 2008 |
| Total Posts: 888 |
|
|
| 23 Jul 2013 12:03 AM |
No no, that's actually pretty simple to do. I don't know why you would do it, but okay.
Basic concept:
MyBigTable = { function(arg) code code code end , function(arg) code code code end , function(arg) code code code end }
You can call these by saying MyBigTable[i](arg), so if you wanted a random function, do MyBigTable[math.random(1,#MyBigTable)](arg)
Specifics, to call the second function, say MyBigTable[2]() |
|
|
| Report Abuse |
|
|
Tuxwonder
|
  |
| Joined: 21 Jan 2008 |
| Total Posts: 888 |
|
|
| 23 Jul 2013 12:03 AM |
| Darn you Cody, how dare you post before me pretty much the exact thing I posted. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2013 12:04 AM |
Actually, you could just do:
local MasterTable = { function() print"FirstCode" end, function() print"SecondCode" end, function() print"ThirdCode" end, }
function RunRandomCode() MasterTable[math.random(#MasterTable)]() end
But the first one feels more organized to me. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2013 12:07 AM |
So as you can see the StringPat table that I put that big piece of code in. That wouldn't work? Or is making that large piece of code a table ok? Is this possible:
MasterTable{"StringPat"} -- Just for example a table that has a table in it. Considering you know that stringpat is the large piece of code. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2013 12:10 AM |
local MasterTable = { ["StringPat"] = function() craft = Instance.new("Message",game.Workspace)
game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(msg) x = player.Name if msg == "string.rep" then craft.Text = ("User "..x.." has won the round, congratulations!") wait(6) craft.Text = ("The Round has Ended") craft.Parent = game.Lighting end end) end)
end, }
MasterTable["StringPat"]() |
|
|
| Report Abuse |
|
|