The Fly and Dig glitch in Pokemon Red, Blue and Yellow
Get fully paralyzed at the top of a Fly, and the game forgets to bring you down. Your Pokemon fights on, and almost nothing can touch it.
The short answer. In Pokemon Red, Blue and Yellow, a Pokemon that is fully paralyzed on the turn it would come down from Fly (or up from Dig) stays invulnerable. The game clears its charging flag but not its invulnerable flag, so it picks moves as normal while every move that rolls to hit misses it, until it uses Fly or Dig to the end again or switches out. Swift and Bide still hit it.
- It needs paralysis. A paralyzed Pokemon is fully paralyzed 63 times in 256 each turn, so about one Fly in four gets stuck.
- Confusion does not do it, though pret's comment says it does: a confusion self-hit clears the invulnerable flag too.
- While stuck, it cannot Transform: the game checks the user's own flag by mistake.
- Tested in the game's own code in an emulator, in Red and Yellow, with Fly and with Dig. How I checked it.
Flag by flag
A Pokemon in battle carries a byte of flags, wPlayerBattleStatus1 (the other side has its own). Fly and Dig use two of them: "charging up" and "invulnerable". Step through it and watch the byte:
The code
ChargeEffect (engine/battle/effects.asm) sets both flags on Fly's first turn. On the second turn, if nothing stops it, PlayerCanExecuteChargingMove clears both and Fly hits:
; pret pokered engine/battle/core.asm PlayerCanExecuteChargingMove: ld hl, wPlayerBattleStatus1 res CHARGING_UP, [hl] res INVULNERABLE, [hl] ... ; CheckPlayerStatusConditions, when it is fully paralyzed .MonHurtItselfOrFullyParalysed ld hl, wPlayerBattleStatus1 ld a, [hl] ; clear bide, thrashing, charging up, and trapping moves such as warp and ~((1 << STORING_ENERGY) | (1 << THRASHING_ABOUT) | (1 << CHARGING_UP) | (1 << USING_TRAPPING_MOVE)) ld [hl], a
Full paralysis jumps to .MonHurtItselfOrFullyParalysed, which clears charging up and leaves invulnerable set. Next turn the Pokemon is not charging, so the battle menu comes back and it picks moves like any other turn. But every move aimed at it goes through MoveHitTest, and there:
bit INVULNERABLE, [hl]
jp nz, .moveMissed ; before any random number is drawn
Nothing clears the flag except finishing a Fly or Dig (the same PlayerCanExecuteChargingMove) or switching out, when a fresh Pokemon's flags are cleared. The other side's routines are copies, so a foe can get stuck the same way.
What still hits it
- Swift.
MoveHitTestreturns for Swift before it looks at the invulnerable flag. In my test Swift hit the stuck Pidgeot and the stuck Dugtrio. - Bide's release. Bide jumps past the hit test when it unleashes. In my test a Chansey's Bide hit the stuck Pidgeot for 234.
- The other side's Transform (its invulnerability check reads the wrong byte on the other side's turn, so it always works), and Haze, which never targets.
- Nothing else that rolls. Thunderbolt, Tackle, Thunder Wave, Toxic, Leech Seed, Night Shade, Seismic Toss: all miss with no roll at all. Explosion misses too, and its user still faints.
Not confusion
pret's comment at PlayerCanExecuteChargingMove says "being fully paralyzed or hurting oneself in confusion removes charging up status resulting in the Pokemon being invulnerable for the whole battle". The code says otherwise for confusion. Before a confused Pokemon hurts itself, CheckPlayerStatusConditions runs:
ld hl, wPlayerBattleStatus1 ld a, [hl] and 1 << CONFUSED ; if mon hurts itself, clear every other status from wPlayerBattleStatus1 ld [hl], a
That keeps only the confusion bit, so invulnerable goes too. In my test a confused Pidgeot flew up, hurt itself on the way down, and Golbat's Wing Attack hit it the next turn. Only full paralysis leaves a Pokemon stuck.
Transform, the other side of the bug
TransformEffect_ (engine/battle/move_effects/transform.asm) was meant to fail against a target in the air or underground, but it reads the wrong byte (pret: "this should be target's BattleStatus1"). On your turn it reads your own flag, so a Pokemon stuck invulnerable cannot Transform: in Red and in Yellow, a stuck Mew's Transform said "But, it failed!". On the other side's turn it reads a number that never has that bit, so the other side's Transform always works, even on you while you are stuck. The battler on this site does the same on both sides.
How I checked it
- Read:
ChargeEffect,PlayerCanExecuteChargingMove,EnemyCanExecuteChargingMove,CheckPlayerStatusConditions,CheckEnemyStatusConditions,MoveHitTestandTransformEffect_in pret's pokered and pokeyellow. - Run in the game: Red and Yellow under the PyBoy emulator, with the battler's battle oracle setting the rolls. A paralyzed Pidgeot was fully paralyzed on its Fly turn: after that, Thunderbolt missed it with no hit roll while it attacked with Quick Attack, and Swift hit. A paralyzed Dugtrio did the same with Dig against Tackle and Swift. A Chansey's Bide hit a stuck Pidgeot. A confused Pidgeot that hurt itself was hit the next turn. A stuck Mew's Transform failed. The battler's engine matched the game everywhere except that last Transform.
- Not tested: anything on a real Game Boy.
Questions
What is the Fly glitch in Pokemon Red and Blue?
If a Pokemon is fully paralyzed on the turn it would come down from Fly (or up from Dig), Red, Blue and Yellow clear its charging flag but leave its invulnerable flag set. It then picks moves as normal, while every move that rolls to hit misses it, until it uses Fly or Dig to the end again or switches out.
How do you do the Fly or Dig invulnerability glitch?
Your Pokemon has to be paralyzed, then use Fly or Dig, then be fully paralyzed on the second turn, when it would attack. Full paralysis happens 63 times in 256 (about 25%) each turn, so a paralyzed Pokemon gets stuck on about one Fly in four.
What can hit a Pokemon stuck invulnerable in Gen 1?
Swift (it skips the hit test), Bide's release (it skips it too), the other side's Transform, and Haze, which affects both sides. Every other move that rolls to hit misses with no roll at all, and status moves fail the same way.
Does confusion cause the Fly glitch too?
No, even though pret's comment on the code says so. When a confused Pokemon hurts itself, the game first clears every battle flag except confusion, the invulnerable one included. Only full paralysis leaves it set.
Is the Fly glitch in Gold and Silver?
This page only covers Red, Blue and Yellow; Gold, Silver and Crystal were rewritten and are not covered here.
Was this tested on a real Game Boy?
No. I read the routines in pret's disassembly and ran the game's own code in the PyBoy emulator, in Red and in Yellow: a paralyzed Pidgeot with Fly and a paralyzed Dugtrio with Dig, each fully paralyzed on purpose. Thunderbolt and Tackle then missed them with no hit roll, while Swift and Bide hit.