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: Could someone explain this please?

Previous Thread :: Next Thread 
nomer888 is not online. 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
tuxedoman23 is not online. tuxedoman23
Joined: 24 Apr 2009
Total Posts: 4670
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. nomer888
Joined: 13 Feb 2010
Total Posts: 551
16 Aug 2013 04:32 PM
Alright, thank you!
Report Abuse
robomax11 is not online. 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 is not online. 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
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