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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 22 May 2011 |
| Total Posts: 278 |
|
|
| 31 Jul 2013 01:50 PM |
| I use notepad to execute scripts in edit mode. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 22 May 2011 |
| Total Posts: 278 |
|
|
| 31 Jul 2013 01:52 PM |
| I understood everything except variables and iterators... |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 22 May 2011 |
| Total Posts: 278 |
|
| |
|
|
| 31 Jul 2013 01:54 PM |
| NEVER use a numeric for loop for iterating through a table! Only use generic! |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|