V. Variables
Variables are used to store information into the memory, if you may want to use them during the actions of the same or even different triggers. There are three categories of variables: Global, Local and Event-Response.
Global Variables are extremely used when making trigger enchanced spells. To declare these variables, you need to go to the variable editor and add a variable. The variable editor can be found in the trigger editor where there is an X icon. The sole advantage of Global Variables is that they can be used by anyone who has little knowledge in triggering. However, they have a big disadvantage as well: they are unique. This means that at a precise moment, the variable can store a single value. If the trigger is executed multiple times, only the value in the last execution will be stored into the variable.
In spellmaking this is a pretty big problem. Consider two units casting the same spell at the same time. If you use global variables, only the second unit casting the spell (because casting EXACTLY at the same time is pretty impossible) will succeed. The first caster’s spell will be bugged, the severity depending on how often you used global variables. As an example, imagine two sorceresses casting slow at the same time, and only the second one’s taking effect. Wouldn’t it be annoying?
The spells that allow two or more units to cast them at the same time without causing any bugs because of the global variables problem are called Multiinstanceable (or MUI). To obtain such spells you will have to use Event-Response Variables (which have their limits) or local variables, which unfortunately for now will be inaccessible to you.
Local Variables unfortunately require JASS, which is already a programming language based on which, triggers were made using a Graphic User Interface (GUI), to make it accessible to everyone. But through this, they had to limit some of the language’s possibilities. I don’t recommend learning JASS until you have considerable experience in triggers. I really found it difficult when I started to learn, and took me more than a month to learn it.
But back to the description of the local variables, they store a separate value for each execution of the actions into the memory. Of course this could cause Memory Leaks (variables are stored into the memory from where they are not disposed) if you do not properly remove them. We will discuss this later, once we finish with the basics.
Event-Response Variables are a little bit different and inflexible. Unlike Global or Local variables, these variables cannot receive a certain value. Their value varies, sole depending on the event of the trigger. Moreover, they have a life limit into the memory. After the shortest period of the time, most of them are disposed from the memory. Only a few of them remain there until the last action has been executed as well. To solve this problem, you will have to use local or global variables.