|
| 23 Apr 2013 07:07 AM |
| I am a bit confused, or is it just a variable. |
|
|
| Report Abuse |
|
|
Voxility
|
  |
| Joined: 15 Apr 2013 |
| Total Posts: 584 |
|
|
| 23 Apr 2013 07:33 AM |
local means it stays in the object like in a function it won't go global. So lets say function a() local var = "asd" end print(var)
It outputs nil because var is a local value instead of global value. |
|
|
| Report Abuse |
|
|
Trioxide
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
| |
|
eletrowiz
|
  |
| Joined: 08 Dec 2008 |
| Total Posts: 12438 |
|
|
| 23 Apr 2013 10:43 AM |
local is mostly used (or what I use it for) for multiple copies of the same variables. Like
for i = 1,10 do local l=i delay(1, function() print(l) end) wait() end
Without the local, it would just print 10 every time.
-={3137}=- |
|
|
| Report Abuse |
|
|
Desperian
|
  |
| Joined: 07 Feb 2012 |
| Total Posts: 3371 |
|
|
| 23 Apr 2013 11:05 AM |
@Electro, Without the local, it would still print 1-10.
e.e |
|
|
| Report Abuse |
|
|
eletrowiz
|
  |
| Joined: 08 Dec 2008 |
| Total Posts: 12438 |
|
|
| 23 Apr 2013 11:07 AM |
Nope.
for i = 1,10 do l=i delay(1, function() print(l) end) wait() end Output; 10 10 10 10 10 10 10 10 10 10
-={3137}=- |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2013 11:09 AM |
Every "Block" has it's own "sphere" of 'local-ness'
A "Block" may be thought-of as anything inside an End.....
if true then local a = 1 print(a) end print(a) -- a no longer exists.
Bite on that, Bri
|
|
|
| Report Abuse |
|
|
Desperian
|
  |
| Joined: 07 Feb 2012 |
| Total Posts: 3371 |
|
|
| 23 Apr 2013 11:09 AM |
MKay, I was personally referring to the fact that that local variable was unneeded and you could simply do,
for i = 1,10 do delay(1, function() print(i) end) wait() end |
|
|
| Report Abuse |
|
|
eletrowiz
|
  |
| Joined: 08 Dec 2008 |
| Total Posts: 12438 |
|
|
| 23 Apr 2013 11:15 AM |
I was using it as an example.
-={3137}=- |
|
|
| Report Abuse |
|
|