|
| 25 Aug 2015 04:49 PM |
| Whats the difference between local and non local variables |
|
|
| Report Abuse |
|
|
|
| 25 Aug 2015 04:54 PM |
Creating a local variable will make it only exist within its own scope (and sub-scopes from that scope). They also are created on register, thus they can be accessed faster.
Creating a non-local variable is called a global variable. Any scope can access it once it exists. However, it is slower to access.
When possible, use locals. In fact, I've NEVER had to create variables without local. Never. Just don't do it. |
|
|
| Report Abuse |
|
|
lostend
|
  |
| Joined: 21 Aug 2011 |
| Total Posts: 8265 |
|
|
| 25 Aug 2015 05:00 PM |
just use local. think of it as identifiying i suppose.
in javascript, you put 'var' in front of variables to make it only accessible in that scope. if you dont, that means that variable already exists
use local to make variables, and not to manipulate them |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 25 Aug 2015 05:17 PM |
local variables can only be called upon or edited via that script
not true for non local variables |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 25 Aug 2015 06:21 PM |
wowgnomes you're wrong, crazyman already explained it.
Global variables are stored in its enclosing's function's environment whereas local variables are stored on the call stack.
A Lua table lookup is much slower than just basic array indexing which is pretty much why local variables are faster. |
|
|
| Report Abuse |
|
|