kinlee01
|
  |
| Joined: 03 Nov 2012 |
| Total Posts: 75 |
|
|
| 23 Sep 2015 04:20 AM |
local function () end
==================
function () end |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2015 04:24 AM |
Local makes a function or variable only limited to a scope. it is usually good to use it when you don't want the function anywhere else.
do function func() print'ellu' end func() -- runs fine end
func() --error |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2015 07:18 AM |
www.lua.org/gems/sample.pdf
Read from page 17. Or read all of it. Your call. |
|
|
| Report Abuse |
|
|
Stymi
|
  |
| Joined: 19 Sep 2015 |
| Total Posts: 1077 |
|
|
| 23 Sep 2015 07:27 AM |
Always use the local keyword if you're defining the function in a code block, but otherwise it's not going to help you at all. Do so if you wish to.
inb4 some scripter who thinks they're the crap starts flaming because there's a 0.0000000000000000000002 second performance benefit |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2015 07:29 AM |
| I would like my 0.0000000000000000000002 seconds back |
|
|
| Report Abuse |
|
|
Stymi
|
  |
| Joined: 19 Sep 2015 |
| Total Posts: 1077 |
|
|
| 23 Sep 2015 07:34 AM |
| But is 0.000000000000000002 seconds worth it if you spend 0.75 seconds typing it? Probably not |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2015 07:34 AM |
| Woah. Looks like someones' got a degree in applied economics. Is that even a thing? |
|
|
| Report Abuse |
|
|
Stymi
|
  |
| Joined: 19 Sep 2015 |
| Total Posts: 1077 |
|
| |
|
|
| 23 Sep 2015 07:38 AM |
| Swag. Looks like SOMEONE (me) has got a degree in applied linguistics |
|
|
| Report Abuse |
|
|
Stymi
|
  |
| Joined: 19 Sep 2015 |
| Total Posts: 1077 |
|
|
| 23 Sep 2015 07:39 AM |
And that is ALSO a thing.
Versus....theoretical linguistics??? |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2015 10:08 AM |
Actually, you should probably use it. Not only is it a good practice that is pretty much how every programming language except Lua works, but it also increases performance SIGNIFICANTLY, especially if you have a loop or are accessing variables (Such as the function itself) quickly. |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2015 10:12 AM |
Roblox staff who makes catalog gear doesn't use it. sloppy af and they capitalize Workspace |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2015 10:28 AM |
| Roblox gear (is in my) socks |
|
|
| Report Abuse |
|
|
kinlee01
|
  |
| Joined: 03 Nov 2012 |
| Total Posts: 75 |
|
|
| 23 Sep 2015 12:16 PM |
Thanks for the Replies guys.
|
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 23 Sep 2015 12:24 PM |
The performance benefit of using local variables is indeed much greater than "0.000000000000000002".
Muad'Dib |
|
|
| Report Abuse |
|
|
Stymi
|
  |
| Joined: 19 Sep 2015 |
| Total Posts: 1077 |
|
|
| 23 Sep 2015 12:33 PM |
No. No it isn't.
Your local variables aren't going to save you. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 23 Sep 2015 12:47 PM |
Oh really? I kinda just did some benchmarks and a simple script that just adds a variable to itself (like this: a = 4; a = a + a) inside a loop and using local variables make it run ~20 seconds faster.
Muad'Dib |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2015 12:49 PM |
| Will it ever even terminate? <.< As far as I can see, it's an infinite loop |
|
|
| Report Abuse |
|
|
Stymi
|
  |
| Joined: 19 Sep 2015 |
| Total Posts: 1077 |
|
|
| 23 Sep 2015 12:52 PM |
> local t1 = tick() local x = 0 for i = 1, 1000000 do x = x + 1 end local t2 = tick() print(t2 - t1) 0.015406608581543 > local t1 = tick() x = 0 for i = 1, 1000000 do x = x + 1 end local t2 = tick() print(t2 - t1) 0.08324408531189
Sure, go ahead and use local variables- I always do! But it's not something that really matters all that much.
|
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 23 Sep 2015 12:52 PM |
If it had never terminated how would I have known how long it took from start to termination?
Muad'Dib |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 23 Sep 2015 01:01 PM |
I re-did my test this time looping a bit higher and the time saved from local variables became ~30 seconds.
--- do local start = tick() local n = 0.1 for i = 1,25000000 do n = n + n end print(tick() - start) --> 53.432 end --- do local start = tick() n = 0.1 for i = 1,25000000 do n = n + n end print(tick() - start) --> 83.347 end ---
Muad'Dib |
|
|
| Report Abuse |
|
|
Stymi
|
  |
| Joined: 19 Sep 2015 |
| Total Posts: 1077 |
|
|
| 23 Sep 2015 01:02 PM |
"for i = 1,25000000 do"
25,000,000
wow 30 seconds on 25 MILLION iteratons big difference |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2015 01:22 PM |
| 25m is a lot, but not unthinkable. But yeah, in the scenarios where 25m iterations of anything ever is required, 30 secs ain't alot. |
|
|
| Report Abuse |
|
|
Luxurize
|
  |
| Joined: 31 Mar 2015 |
| Total Posts: 1289 |
|
|
| 23 Sep 2015 01:25 PM |
'local' before a function is only good if you're only going to call that function once.
“Insane isn't always black or white. We're all pathological, in our own ways.” |
|
|
| Report Abuse |
|
|
Stymi
|
  |
| Joined: 19 Sep 2015 |
| Total Posts: 1077 |
|
|
| 23 Sep 2015 01:27 PM |
"'local' before a function is only good if you're only going to call that function once."
What? No... That's just completely wrong.
And yeah, they're not necessary. 30 seconds on 2.5m iterations as the other guy said, is not going to make a very big difference. |
|
|
| Report Abuse |
|
|