YesNoOk
avatar

ChangeAnim and ChangeAnim2 (SCTRL) (Read 7587 times)

Started by Ricepigeon, October 20, 2015, 04:35:15 PM
Share this topic:
ChangeAnim and ChangeAnim2 (SCTRL)
#1  October 20, 2015, 04:35:15 PM
  • *****
  • Gaps? Where we're going, we don't need gaps...
    • USA
    • ricepigeon.neocities.org
ChangeAnim changes the action number of the player's animation to the animation number in the player's AIR file. ChangeAnim2 is like ChangeAnim, except this controller should be used if you have placed P2 in a custom state via a hit and wish to change P2's animation to one specified in P1's air file. For example, when making throws, use this to change P2 to a being-thrown animation.

Required parameters:

    value = anim_no (int)
        anim_no is the action number to change to.

Optional parameters:

    elem = elem_no (int)
        elem_no is the element number within the specified action to start from.

Additional Notes:
If you have Player2 in a custom state, and wish to use ChangeAnim in order to change them to an animation located in their own AIR file, it is typically good practice to use the SelfAnimExist trigger, with a ChangeAnim2 as a failsafe in case SelfAnimExist returns false. For example, assuming that Player2 is in a custom state with the following code;

Example:
Code:
[State 2050, CA]
type = changeanim
trigger1 = time = 0
trigger1 = selfanimexist(5060)
value = 5060

[State 2050, CA2]
type = changeanim2
trigger1 = time = 0
trigger1 = !selfanimexist(5060)
value = 2050

The above code will change Player2 to his own animation number 5060 if animation 5060 exists in Player2's AIR file, otherwise it will change Player2 to Player1's animation 2050 if animation 5060 does not exist in Player2's AIR file. Examples of where you may wish to use such code include Throw Escapes, Guard Crushes, Demitri's Midnight Bliss, Cheese KOs, and Dizzy states.
Last Edit: March 24, 2018, 07:57:05 PM by Odb718
Re: ChangeAnim and ChangeAnim2 (SCTRL)
#2  September 29, 2016, 07:22:21 PM
  • *****
  • Gaps? Where we're going, we don't need gaps...
    • USA
    • ricepigeon.neocities.org
After some research, I should note that attempting to change to a specific animation element using Changeanim will only put you at the first possible tick of the animation element (assuming that the animelem has a duration of longer than 1 tick). Thus, if you attempt to use changeanim with animelemno(0) to "lock" the player's animation, such as during an armor state, note that you will be resetting that animation element back to the beginning of its duration.

See this thread for more information.
Re: ChangeAnim and ChangeAnim2 (SCTRL)
#3  February 09, 2021, 02:15:21 PM
  • avatar
  • *
    • Canada
There’s a bug in the way ChangeAnim/ChangeAnim2 are handled for custom states, fortunately it’s not very likely to come up so long as appropriate SelfAnimExist checks are used

Internally to MUGEN, a character’s animation is stored as the index of that animation in the AIR file (ie first anim in the AIR is index 0, second is index 1, ...)

When ChangeAnim2 is successfully executed, the matching index from the AIR file of the custom stator is used (ex, I custom state the opponent and CA2 to 5155, which is index 50 in my AIR file; anim number for the opponent internally is updated to 50), and a flag is set to indicate whose AIR data to use

If ChangeAnim is then executed within the same custom state, and the ChangeAnim has an invalid animation number specified, the flag for whose AIR data to use is cleared, but the index remains at whatever it was after the ChangeAnim2 (for the above example, 50). This is because ChangeAnim will refuse to change to an invalid anim, but the AIR data flag is cleared without this check. So in this example, the custom stated opponent jumps from my 50th animation to their 50th animation. This can cause obvious visual errors (since the opponent’s ‘n’th animation is unlikely to be what I want to show), or even hard crashes (if the opponent’s AIR file has less than ‘n’ animations, random junk data will get loaded from memory as the current anim and will very likely crash with no error)

This shouldn’t ever come up in a normal character, since you should use SelfAnimExist to avoid ChangeAnim to an invalid value. But here’s an example of how it could go wrong with a missing SelfAnimExist guard on a ChangeAnim. In this case, if the CA2 activates, we know 5060 does not exist, so the subsequent ChangeAnim will trigger the bug.

Code:
[State 1234, CA2]
type = ChangeAnim2
trigger1 = Time = 0
trigger1 = !SelfAnimExist(5060)
value = 2050

[State 1234, CA]
type = ChangeAnim
trigger1 = Time = 0
value = 5060