globalscope vs local variables

 

Just a snippet of information that I have not seen written into the documentation it might be useful to someone when debugging. I accidentally declared a variable both globalscope and localy it works in the following way.

If a variable is declared globalscope and a variable of the same name is declared locally, the local variable takes precedence in it's function and changes to the value of that variable in it's function, only affects the local version of that variable, the global version remains unchanged. This was the cause of a bug that took me all day to find :(

 
SDC:

Just a snippet of information that I have not seen written into the documentation it might be useful to someone when debugging. I accidentally declared a variable both globalscope and localy it works in the following way.

If a variable is declared globalscope and a variable of the same name is declared locally, the local variable takes precedence in it's function and changes to the value of that variable in it's function, only affects the local version of that variable, the global version remains unchanged. This was the cause of a bug that took me all day to find :(

I ran into this a long time ago. Then I read it's bad practice to make a global variable and local variable the same name. Some naming convention is starting global variables with _underscore and others is with Capitalization while local variables starts with non-caps. Some editors would flag this problem but meta-editor4 doesn't. Anyways, once you know which one takes priority, it makes it easier to ketch this error in the future 8P.
 

Yes what i did was bad practice, I dont think I'll be making that mistake again lol

 
You don't make that error with a naming convention. Ubzen suggested underscore/capitalization. I use noDots=local, dotted.variable=global, Capitalized.Variable=external global. Just be consistent.
Reason: