Lecturous
|
  |
| Joined: 17 Aug 2013 |
| Total Posts: 1096 |
|
|
| 10 Oct 2015 09:10 PM |
I know how to code, but I think my code isn't efficient. Can you guys help my code be more efficient/show me examples of efficient code?
~ [ E> ] My heart is metallic, but it still has feelings. ~ |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 10 Oct 2015 09:15 PM |
Local variables Numeric for loops Events instead of constant looping
|
|
|
| Report Abuse |
|
|
|
| 10 Oct 2015 09:17 PM |
| How are numeric for loops more efficient than pairs or similar? |
|
|
| Report Abuse |
|
|
gangman67
|
  |
| Joined: 04 Jun 2011 |
| Total Posts: 798 |
|
|
| 10 Oct 2015 09:32 PM |
| @Lec, Idk cnt yelled at me for saying that before but never provided proof of why but the example I used it for was getting children and here > http://wiki.roblox.com/index.php?title=API:Class/Instance/GetChildren Roblox even recommends Generic loops over numerical ones http://wiki.roblox.com/index.php?title=Generic_for that will explain more on generic loops, But really It just depends on what you are doing with the loop like numerical loops should just be used with stuff that doesn't have a iterator other than that I would stick to generic loops. |
|
|
| Report Abuse |
|
|
|
| 10 Oct 2015 09:33 PM |
| You know how much of the time you need to clone a scripted object multiple times in one place? Well, I use one script in the ServerScriptService to search for specific objects in the workspace and assign event listeners and functions to each of the same creed. Maybe you could try that? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 10 Oct 2015 09:40 PM |
I did explain it, you probably just didn't understand it. Generic for loops by nature are slower, they require function calls each iteration and some iterators are not stateless, causing overhead. |
|
|
| Report Abuse |
|
|
gangman67
|
  |
| Joined: 04 Jun 2011 |
| Total Posts: 798 |
|
|
| 10 Oct 2015 09:46 PM |
| I can see why it would use more resources now but why does the wiki recommend it over numerical for loops? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 10 Oct 2015 09:47 PM |
| Because the wiki is stupid. |
|
|
| Report Abuse |
|
|
gangman67
|
  |
| Joined: 04 Jun 2011 |
| Total Posts: 798 |
|
| |
|