There's a very simple solution to all this: Don't use global variables. That's not entirely true because AutoIt more or less forces you to use global variables for a lot of stuff. However, proper hiding the variable behind an API makes them safe.