Var and FVar (Triggers) (Read 8069 times)

Started by Ricepigeon, September 29, 2015, 07:12:28 PM
Share this topic:
Var and FVar (Triggers)
New #1  September 29, 2015, 07:12:28 PM
  • *****
  • Gaps? Where we're going, we don't need gaps...
    • USA
These triggers take a mandatory variable number as an argument. It returns the value of the player's specified int (Var) or float (FVar) variable.

    1.) Var(exprn)
    2.) FVar(exprn)
        An expression evaluating to a variable number.
        Valid numbers for Var are 0-59, while valid numbers for FVar are 0-39.

Return type:
    int (Var only)
    float (FVar only)
Error conditions:
    Returns bottom if exprn evaluates to bottom, or if exprn evaluates to an invalid variable index.

;Triggers if the value of variable 0 is -34.
trigger1 = Var(0) = -34

;Triggers if the value of float variable 5 is -1.23.
trigger1 = FVar(5) = -1.23

Related SCTRL:
VarAdd (SCTRLs)
VarRandom (SCTRLs)
VarRangeSet (SCTRLs)
VarSet (SCTRLs)

Related Triggers: 
SysVar (Triggers)
SysFVar (Triggers)
StageVar(*,***) (Triggers)

Related CNS:
IntPersistIndex & FloatPersistIndex  -  Player Variables (CNS)

Additional Notes:
When using Var or FVar in an assignment operator within a trigger, the expression will not only set the variable equal to that value, but will also return that value as the result of that expression. For example;

trigger1 = Var(0) := 0

In this example, Var(0) is set to 0, and also returns 0 as the value of the expression. Since 0 is the boolean equivalent of false, this will never trigger, and will skip to Trigger2, if any. When using the assignment operator within a trigger line, if that assignment operation sets the value of your variable to 0 and you still want the SCTRL to trigger, you should include the variable assignment within an OR statement to ensure that the trigger still works. For example:

[State 2000, ChangeState]
type = ChangeState
trigger1 = time = 100
trigger1 = (Var(0) := 0) || 1
value = 2001

In the above code, when time is equal to 100, the value of Var(0) will be set to 0. Normally, because this expression is returning 0, the Changestate to state 2001 will never occur. However, the OR statement in the second trigger1 prevents this from happening, as 0 || 1 equates to 1, the boolean value for true, thus as long as the variable assignment occurs, so will the ChangeState to state 2001.

Read This if you have any trouble understanding variables!
Last Edit: January 07, 2017, 02:25:35 PM by Odb718
Re: Var and FVar (Triggers)
#2  December 10, 2015, 02:21:06 PM
  • *****
  • Shame on you!
    • USA
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]
type = VarSet
trigger1 = (Time%1) = 0
v = 12 
value = floor( (enemy,const(size.head.pos.y) - enemy,const(size.mid.pos.y) )/2 )
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.
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.

vVv Mauru Mauru Released vVv