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: Tables + Index Random Table Value

Previous Thread :: Next Thread 
MasterTrident is not online. MasterTrident
Joined: 11 Jun 2013
Total Posts: 25
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 is not online. 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
MasterTrident is not online. MasterTrident
Joined: 11 Jun 2013
Total Posts: 25
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
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
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 is not online. 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 is not online. 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
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
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
MasterTrident is not online. MasterTrident
Joined: 11 Jun 2013
Total Posts: 25
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
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
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
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