Variables are placeholders. In mugen, and all coding, you need to compare situations. With in each State the character enters, Mugen has predefined info it can find out. Those are the triggers.
Variables are used to create questions and/or answers Mugen isn't intrinsically built to handle. They can be used to shorten Sctrl's trigger questions and other places math is used.
[State 1350, Chest Finder]The exact spot between P2's head and midsection isn't something Mugen can instantly look up. With the help of Var(12) I can refer to that spot without having to do the math over and over. In some cases, like in a hitdef, the math used to come up with the Y position wouldn't be possible. A variable would have to be predefined.
type = VarSet
trigger1 = (Time%1) = 0
v = 12
value = floor( (enemy,const(size.head.pos.y) - enemy,const(size.mid.pos.y) )/2 )
As you may have noticed I set the variable in state 1350. Mugen can then use the last value for Var(12) in any other state. It's a way of making Mugen remember things you want. If there's a value you create in one state, say an amount of damage a super does to P2, and in another state you want to give that exact value as health back to P1, you'd define it as a variable. The info would transfer states.
On top of being able to remember from state to state is the ability to reset and redefine the variable at will. Some characters will use a variable to remember, or convert, which button press triggered the particular move to happen. Say, medium punch was used to spawn a fireball. Typically the variable would be set to 2. 1 would be light punch, and 3 would be fierce punch. Then in the dragon punch state we could redefine what button press was used and set it to the correct version. Because of the value differences we can use the var with math to increase velocities, damage, and other differences between the 3 strengths of the move. Damage = 10*Var(12) would produce, 10, 20, and 30 for light, medium, fierce.
Each time the fireball or dragon punch is activated the proper version would work all within one State.
One thing most people new to variables don't get right away is the difference between integers and float variables.
int (Var) means it's a solid,or whole, number. -12345
float (FVar) means it has a decimal point. -123.45
Var will be used far more often than FVar.
With some help both can become interchangeable using math. FVar can use floor() or Ceil() to become a whole number and Var*1.0 can add the float aspect. (correct me if I'm wrong)
Sometimes you'll find the math just isn't working exactly how you need. It may need to use FVar instead of Var, and vice versa.