people tell me i should put local in front of my variables but why
local
variables is deemed to be a better practice because:
01 | for i = 0 , 10 do |
02 | local x = i; |
03 | end |
04 |
05 | print (x); --nil |
06 |
07 | for i = 1 , 100 do |
08 | local y = i + 100 ; |
09 | end |
10 |
11 | print (y); --nil |
Even if you really wanted to use global variables, you could simply declare local variables at the beginning of your script....
01 | local x = 0 ; |
02 |
03 | while x < 10 do |
04 | x = x + 1 ; |
05 | end |
06 |
07 | print (x); -- 10 |
08 |
09 | while x < 100 do |
10 | x = x + 1 ; |
11 | end |
12 |
13 | print (x); -- 100 |
14 |
15 | while x < 50 do |
Unless there are specific scenarios where it is an absolute requirement.