Sometimes in the development of a program you change the way a function works, and declare new variables to natch the way the modified function works. Be sure to clean up any old variables you may have set for the prior version. It would be easy to say global variables should never be used, but this is not the case. There are times when the only way to get something done is with a global variable. Fortunately this is rarely the case.
Global variables have many problems associated with thier usage.
No one of these problems are any worse than the next, they are all bad and should be avoided. If you have failed to initialize your data prior to usage, a global variable will return you the last value that it held. This means global indexs will be wrong, global values of length or position will be wrong, and any other value you make global will probably also be wrong. A global variable can be changed by any function in your program. Its scope is limited only by the current drawing session.