|
| 12 Mar 2016 04:12 PM |
so i could do
local c = object:GetChildren() for i=1, #c do -- then add a transparency changing loop here
but that would change the transparency of only one of the children at a time and since its a loop it'd never move onto the next child. How do I change the transparency over and over again for EVERY child all at one time? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 12 Mar 2016 04:15 PM |
| Multiple iterations. Move your transparency loop outside and your child iteration loop inside. |
|
|
| Report Abuse |
|
|
SourHaze
|
  |
| Joined: 15 Dec 2008 |
| Total Posts: 588 |
|
|
| 12 Mar 2016 04:24 PM |
"since its a loop it'd never move onto the next child"
You lost me here. The point of an iteration loop is moving onto every child.
|
|
|
| Report Abuse |
|
|
SourHaze
|
  |
| Joined: 15 Dec 2008 |
| Total Posts: 588 |
|
|
| 12 Mar 2016 04:27 PM |
I have some advice outside of the question you asked though. You seem to be iterating like this:
for i = 1, #c to -- i is the amount of iterations -- c[i] is the instance end
But there is a built-in way to do it much more reliably. You can use something called an iterator function as a part of your for loop. There is a built in one called pairs. Look:
for i, v in pairs(c) do -- i is the amount of iterations -- v is the instance end
|
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 12 Mar 2016 04:28 PM |
| Even though pairs is slower, and the way he had works perfectly fine. |
|
|
| Report Abuse |
|
|
SourHaze
|
  |
| Joined: 15 Dec 2008 |
| Total Posts: 588 |
|
|
| 12 Mar 2016 04:34 PM |
"Even though pairs is slower, and the way he had works perfectly fine."
The way he does it isn't guaranteed to cover everything or iterate in the right order. If speed is a problem, use this instead:
for i, v in next, c do -- etc end
|
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 04:36 PM |
"But there is a built-in way to do it much more reliably" Learn what reliable means
"The way he does it isn't guaranteed to cover everything or iterate in the right order" You're stupid
"If speed is a problem, use this instead:" Even more stupid |
|
|
| Report Abuse |
|
|
SourHaze
|
  |
| Joined: 15 Dec 2008 |
| Total Posts: 588 |
|
|
| 12 Mar 2016 04:38 PM |
"Learn what reliable means"
re·li·a·ble rəˈlīəb(ə)l/ adjective 1. consistently good in quality or performance; able to be trusted.
"You're stupid"
Are you going to call me stupid, or explain why I'm wrong? You're the only one who doesn't seem to understand how things work.
|
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 04:39 PM |
If you need me to explain why you're wrong, then you don't know the Lua language.
A numerical for loop is just as reliable for iterating over arrays, which is what GetChildren returns.
A numerical for loop is obviously going to go in order, if anything pairs is more misleading.
Using next doesn't actually make iteration faster at all. |
|
|
| Report Abuse |
|
|
SourHaze
|
  |
| Joined: 15 Dec 2008 |
| Total Posts: 588 |
|
|
| 12 Mar 2016 04:44 PM |
"If you need me to explain why you're wrong, then you don't know the Lua language."
I know the Lua language well enough to script using it. Your definition of knowing something seems very exclusive.
"A numerical for loop is just as reliable for iterating over arrays, which is what GetChildren returns."
Okay, you could have saved trouble by saying this at first instead of attacking me. You're just as grumpy as every arrogant elitist here.
"A numerical for loop is obviously going to go in order, if anything pairs is more misleading."
I am pretty sure that pairs is, if not better, on the same level as a numerical for loop.
"Using next doesn't actually make iteration faster at all."
It makes the execution much faster. The pairs function uses next to iterate, so it's the difference between doing a task and calling a function to do that task. Calling a function creates a little bit of an extra delay.
|
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 04:46 PM |
"I am pretty sure that pairs is, if not better, on the same level as a numerical for loop." Pairs is meant to go over all keys of a table. You don't compare them. It's misleading because a numerical for loop is explicit in how it's iterating.
"It makes the execution much faster. The pairs function uses next to iterate, so it's the difference between doing a task and calling a function to do that task. Calling a function creates a little bit of an extra delay." If you think a single function call BEFORE the loop actually is executed causes it to be "much faster" than you're an idiot. |
|
|
| Report Abuse |
|
|
SourHaze
|
  |
| Joined: 15 Dec 2008 |
| Total Posts: 588 |
|
|
| 12 Mar 2016 04:49 PM |
"If you think a single function call BEFORE the loop actually is executed causes it to be "much faster" than you're an idiot."
It doesn't matter to me, but eLunate pointed out that pairs is slower, so I fixed it. If you're the kind of person who cares about maximum efficiency then it certainly matters.
And let me talk about your anger issues. Did somebody frustrate you so you feel the need to go around insulting others? This is a help forum, and you're the only person posting here who feels the need to be aggressive. It makes you look like a jerk to anybody reading through this thread.
|
|
|
| Report Abuse |
|
|
jode6543
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 5363 |
|
|
| 12 Mar 2016 04:50 PM |
@SourHaze I would highly advice you to ignore Flux. He's just trying to stir up trouble, is not contributing anything meaningful to the discussion.
@Flux Google "Graham's Hierarchy of Disagreement". Assuming you are actually attempting to get someone to agree with you -- if not, you are simply trolling -- you should refrain from primarily drawing on ad hominem to make your points. |
|
|
| Report Abuse |
|
|
darthpyro
|
  |
| Joined: 18 Aug 2009 |
| Total Posts: 3569 |
|
|
| 12 Mar 2016 04:50 PM |
https://springrts.com/wiki/Lua_Performance#TEST_9:_for-loops
|
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 04:50 PM |
"It doesn't matter to me, but eLunate pointed out that pairs is slower, so I fixed it. If you're the kind of person who cares about maximum efficiency then it certainly matters." She pointed that out because a numerical for loop (what the OP had originally) is ACTUALLY FASTER than using a generical for loop. |
|
|
| Report Abuse |
|
|
jode6543
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 5363 |
|
|
| 12 Mar 2016 04:50 PM |
| Whoops, *and is not contributing |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 04:51 PM |
| jode, you sound like a sensitive edgy little skid (just like sourhaze). If you think I haven't contributed (guaranteed I've contributed more than all of you combined times 5) then you should seriously rethink your life. |
|
|
| Report Abuse |
|
|
0_0
|
  |
| Joined: 15 Aug 2010 |
| Total Posts: 75 |
|
|
| 12 Mar 2016 04:52 PM |
| https://medium.com/@RBX_Crazyman32/don-t-use-next-instead-of-pairs-6758bb19de61#.yg88re9ac |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 05:00 PM |
While flux may be aggressively issuing points, his points are true....
Using next or pairs is slower than a numerical for loop.
The answer to the problem has already been issued as well... although code was not posted....
local children = object:GetChildren(); for i = 1, 10 do for x=1,#children do children[x].Transparency =( i/10)%1; end wait(); end
That is assuming all the children are guaranteed to be parts... otherwise you have two options...
1. Depending on length of this code being ran through you should go through children and create a new table of children that are guaranteed to be parts.
2. If the length this code will be ran is minimal add the check inside the inner for loop. |
|
|
| Report Abuse |
|
|