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: is there like table.random

Previous Thread :: Next Thread 
rny is not online. rny
Joined: 26 Jul 2009
Total Posts: 5079
13 Apr 2014 06:47 PM
cause if i do table.insert(1, #Table_Name) it'll insert a number
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
13 Apr 2014 06:48 PM
table.insert(math.random(), #Table_Name)
Report Abuse
rny is not online. rny
Joined: 26 Jul 2009
Total Posts: 5079
13 Apr 2014 06:53 PM
does that get a random variable from the table
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
13 Apr 2014 07:01 PM
Example:

--maps
maps = {
Bricktops
Meadows
Pitgrounds
}

map = (math.random(1,#maps))

newMap = game.Lighting:FindFirstChild(tostring(maps[map])):Clone()
newMap.Parent = workspace

This works, because you can get something inside a table using 'ExactTableName[Number]'
The number indicates which variable. For example, to get Bricktops, it would be maps[1], to get meadows, maps[2], or to get pitgrounds, maps[3]. And this would go so on. You should get it now.

So math random would work. It takes the number of maps, and chooses it randomly. Then, since you can use maps[number] to get the variable, it does this: maps[RandomNumberHereFrom1ThroughHowManyVariables]

This would do this exactly:

>Choose a random map (Even though it isn't a TRUE random number generator)
>And parent it to workspace (This would only work if it is the EXACT name of a map in lighting, but string.lower can be used)

And tostring is required, because the variables aren't strings.

Sorry for any bad explanations, etc. This is just how I see it.
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
13 Apr 2014 07:07 PM
Lol he's asking for this..

Table = {
variable1
variable2
variable3
}

Picked_Variable = (Table[math.random(1,#Table)])

print(Picked_Variable)

You use the math.random method on the statistics of a table.
Report Abuse
rny is not online. rny
Joined: 26 Jul 2009
Total Posts: 5079
17 Apr 2014 02:31 PM
i just winged it and did this


local Number = math.random(1,#Spectators);local Add = Spectators[Number]
table.insert(Hit_Men, Add);table.remove(Spectators, Number)
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