This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ETHANATOR360's profile picture

[lua] [question] why should i use local variables?

Started by ETHANATOR360, 16 July 2012 - 07:11 PM
ETHANATOR360 #1
Posted 16 July 2012 - 09:11 PM
iv seen most people global using local variables in there programs and i want to know why should use them
MysticT #2
Posted 16 July 2012 - 09:35 PM
Well, it's bad practice to use global variables. Any program can access them, so it brings security isues. If the only program running is yours, then it should be ok. But you can't ensure that (there could be some program running on the background), and one could mess up the other (you expected a variable to be of some type, but it changed in the other program and now your program crashes).
Also, global variables stay when the program ends, so you shouldn't store anything like passwords, etc. cause other program could read them.
ETHANATOR360 #3
Posted 16 July 2012 - 09:50 PM
thanks :P/>/>