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: math.random?

Previous Thread :: Next Thread 
blimp80 is not online. blimp80
Joined: 22 May 2011
Total Posts: 278
31 Jul 2013 01:44 PM
Lets say I have 200 green parts.
I need a script that will take half of them randomly and turn brown.
Anyone?
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
31 Jul 2013 01:45 PM
for variables in iterator, table do
if math.random() < 0.5 then
part.BrickColor == BrickColor.new("Brown")
end
end
Report Abuse
blimp80 is not online. blimp80
Joined: 22 May 2011
Total Posts: 278
31 Jul 2013 01:48 PM
I'm sorry, could you be more specific?
I'm terrible at this stuff.
Lets say the 200 parts were named Brick.
I just need a script I can put into notepad and execute.
Thank you.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
31 Jul 2013 01:49 PM
"notepad and execute"

lolwut?

And look up Generic for loops on the wiki. They should help with what I missed out.
Report Abuse
blimp80 is not online. blimp80
Joined: 22 May 2011
Total Posts: 278
31 Jul 2013 01:50 PM
I use notepad to execute scripts in edit mode.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
31 Jul 2013 01:51 PM
Ok... Anyway, I encourage you thinking for yourself. Look at the wiki and if you dont understand something, post here.
Report Abuse
blimp80 is not online. blimp80
Joined: 22 May 2011
Total Posts: 278
31 Jul 2013 01:52 PM
I understood everything except variables and iterators...
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
31 Jul 2013 01:53 PM
local g = model:GetChildren()

for i=1, #g do
local ge[i] = math.random(0,1)
if ge[i] == 1 then
g[i].BrickColor == BrickColor.new("Brown")
end
end
Report Abuse
blimp80 is not online. blimp80
Joined: 22 May 2011
Total Posts: 278
31 Jul 2013 01:54 PM
Thank you.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
31 Jul 2013 01:54 PM
NEVER use a numeric for loop for iterating through a table! Only use generic!
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
31 Jul 2013 02:06 PM
"NEVER use a numeric for loop for iterating through a table! Only use generic!'

that's bad advice.

Technically, numeric for loops are faster (not by much) than generic for loops.

I just use generic loops because it already has a local variable as value and index.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
31 Jul 2013 02:07 PM
I'm sorry to say that's bad advice. It's not bad advice.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
31 Jul 2013 02:09 PM
but I was true about numeric loops being faster, lol

Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
31 Jul 2013 02:14 PM
But then you need to set the value to a variable... Did you factor that in? And it cannot iterate through non-numeric indexes, or through gaps in indexes.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
31 Jul 2013 02:19 PM
for i,v in pairs(tab) do v.s for i = 1,#tab do

1. Generic for loop uses a function (pairs or next), which has a few lines of code. A numeric loop uses numbers.

2. i,v are two variables in the stack. You only use 1 for numeric


Numeric values are faster and for proof look at your multi-core processors.
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