nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 16 Aug 2013 03:39 PM |
I was looking at math.random in Mathematical Functions on the ROBLOX wiki, and found this:
local list = Workspace:GetChildren() print( list[math.random(#list)] )
I was wondering why the first pair of parentheses and "list[]" were needed. Could someone please explain this? |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2013 04:18 PM |
I think list serves as a table in this script, and the print function prints the name of a random Child of Workspace.
~Try my new game, Volcano Survival!~
http://www.roblox.com/Volcano-Survival-8-15-13-SHOP-GAME-PASS-ADDED-place?id=122351602 |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 16 Aug 2013 04:20 PM |
| I'm guessing since we're trying to access a tables value (such as tab[1];tab[2], etc), we still have to do it to randomize the values. Just a guess |
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 16 Aug 2013 04:26 PM |
Alright, I understand now. Thank you guys!
I was also wondering, say I clone four random parts from a table of eight, such as
local parts=game.Lighting.Blocks:GetChildren() for i=1,4 do local blocks=parts[math.random(#parts)]:Clone() blocks.Parent=Workspace.Blocks end
How would I make sure that no two parts are cloned twice? |
|
|
| Report Abuse |
|
|
Zomebody
|
  |
| Joined: 01 Jun 2010 |
| Total Posts: 789 |
|
|
| 16 Aug 2013 04:28 PM |
| put the random four blocks in a new table. Then check whether or not the blocks you clone is inside the new table you made by using a for loop. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 16 Aug 2013 04:31 PM |
It won't clone twice, it's a for loop, there's a max to it.
Just in case, put this before the loop.
db = false if not db then db = true
Then after you parent the block, add this after it
db = false end |
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
| |
|
robomax11
|
  |
| Joined: 07 Jul 2011 |
| Total Posts: 6828 |
|
|
| 16 Aug 2013 04:39 PM |
| then wut would the final script look like? |
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 16 Aug 2013 09:10 PM |
Sorry for the delay.
Zomebody, I'm not sure if you understood me or I misunderstood you. Say I run that script, four random bricks out of eight will be cloned.. If brick 1, 2, 2, and 7 randomly spawn, how could I prevent or remove any duplicate bricks, no matter the number?
Thank you, Infocus. Unfortunately that is not what I needed, I poorly explained what I needed, sorry. |
|
|
| Report Abuse |
|
|