SlideShare a Scribd company logo
1 of 37
Download to read offline
How The Long-Range
Trainer Escape Glitch
(Mew Trick) Works
but like.. technically speaking
Agenda
● Background
● Mew Trick Description
● Technical Analysis
○ Glitch
■ CheckFightingMapTrainers vs. UpdateSprites
○ Setup
■ DisplayEnemyTrainerTextAndStartBattle
○ Final Step
■ InitBattleEnemyParameters
Background
● It was impossible to get Mew, except by attending Nintendo events, as such
it was very exclusive.
● There was a rumour that you could get Mew behind a truck in SS. Anne, but
it wasn't true. Many similar rumours turned out to be false as well.
Background
● However, one of those rumours turned out to be true!
● And at first, it seemed like yet another scam.
Background
Apparently first publicly described in March 2003 by Daniel26, but TheScythe
made it popular in a forum a month later in in April (and later on analyzed in depth
by WhteCat). Daniel26 explained the glitch like this:
Ok, first you must not battled the youngster that has a slowpoke (the one past nugget bridge he's
the one looking up, about the 4th trainer)and not battled the gambler next to the right entrance to
saffron city. THE CODE:fly to saffron city go out the right exit, go up to the door little house (don't go
in) press down, quickly press start(before the ! comes onto the gamblers head) fly to cerulan city, go
up nugget bridge battle the youngster, walk where he is looking,(when you walk in front of him make
sure you have 1 or 2 squares away from him) let him walk to you then he will battle you, after the
battle fly to saffron city, try going out the right side exit again, the menu will pop up,press b to get off
it then the screen will flash like when a pokemon appears in the grass, and a wild MEW at LV:7 will
appear.
Pre-requisites
● not battled the youngster that has a
slowpoke (the one past nugget bridge he's
the one looking up, about the 4th trainer)
● not battled the gambler next to the right
entrance to saffron city
The Glitch
● go up to the door little house (don't go in) press down, quickly press start
The Glitch
● (before the ! comes onto the gamblers head) fly to cerulan city
● fly to cerulan city, go up nugget bridge battle the youngster, walk where he is
looking,(when you walk in front of him make sure you have 1 or 2 squares
away from him) let him walk to you then he will battle you,
The Setup
The Last Step
● after the battle fly to saffron city, try going out the right side exit again, the
menu will pop up,press b to get off it
The Last Step
● then the screen will flash like when a pokemon appears in the grass, and a
wild MEW at LV:7 will appear
How does that work?
Technical Analysis
● The Glitch
○ Escaping from a battle by flying away
● The Setup
○ Fighting with the slowpoke youngster
● The Last Step
○ Going back to where you ran away
Sources
WhteCat analyzed the glitch and published his notes on "The P Files"
github.com/pret has a disassembled version of most Pokemon games
Vocabulary
● Trainer
○ An enemy that will fight you if it sees you.
● Sprite
○ Any in-game object, like a trainer, a door, and so on.
Technical Background
● GameBoy works the following way:
○ The screen is drawn
○ Code is executed
○ The screen is drawn
○ Code is executed
○ The screen is drawn
○ Code is executed
○ The screen is drawn
○ Code is executed
○ …
● What is drawn on the screen depends on what the code that ran before says
Technical Background
● The code (among other things) does:
○ Walking Animation (move the world around the user)
○ Run Map Scripts (code specific to this part of the world)
○ Detect Buttons (if the user pressed any buttons)
○ Check START Menu (if the user pressed the START button)
● The memory (among other things) contains:
○ Temporal memory for holding in-game data.
○ Medium term memory for storing the state in every map.
○ Read only memory for holding the game's code.
Map Scripts
● Most maps contain 3 map scripts:
○ CheckFightingMapTrainers
○ DisplayEnemyTrainerTextAndStartBattle
○ EndTrainerBattle
● CheckFightingMapTrainers
○ code responsible for detecting if any trainer can see the player and then having them walk-up
to the player
● DisplayEnemyTrainerTextAndStartBattle
○ runs after the previous script, and shows the pre-battle text and starts the battle
● EndTrainerBattle
○ finishes the battle and lets the user continue
CheckFightingMapTrainers vs. UpdateSprites
● UpdateSprites: Loop over all Sprites
○ Animate sprites (most move even if static)
○ But don't update sprites if currently walking
● CheckFightingMapTrainers: Loop over all Trainers in the map
○ Ignore those that aren't currently visible
○ If the trainer is looking at the user, fight!
This is where the glitch happens!
The Glitch
● At first, since the player just moved down, the trainer is not yet visible, and so,
can't engage the player. So the player has a single turn to do something
before the trainer becomes visible.
CheckFightingMapTrainers vs. UpdateSprites
● UpdateSprites: Loop over all
Sprites
○ Animate sprites (most
move even if static)
○ But don't update sprites if
currently walking
● CheckFightingMapTrainers:
Loop over all Trainers in the
map
○ Ignore those that aren't
currently visible
○ If the trainer is looking at
the user, fight!
CheckFightingMapTrainers vs. UpdateSprites
● The Glitch is simply that there is a "turn" during which the user can do
something (move out, or press START) when the Trainer is not yet visible.
Teleport / Fly
● When the user Teleports / Flies to somewhere else, the trainer has no time to
start the battle, but has enough time to move the script for the current map to
DisplayEnemyTrainerTextAndStartBattle
DisplayEnemyTrainerTextAndStartBattle
● The Script does the following:
○ Wait for the trainer to finish walking to the player (marked by memory 0xD730)
○ Re-enable the joystick controls (set [wJoyIgnore] = 0)
○ Display the Before Battle Text (marked in wSpriteIndex)
○ Start Battle
Teleport / Fly
● When the user Teleports/Flies to another map, the following happens:
○ The current map is left in it's current state
■ This means the "active" script in the current map (route 8) is left as
DisplayEnemyTrainerTextAndStartBattle waiting for memory 0xD730 to be 0.
○ The map where you are flying to is set as the new "current" map.
■ The state for each map is stored separately, so this simply leaves the previous state
untouched.
● So the Script in the map for Route 8 is left as
DisplayEnemyTrainerTextAndStartBattle, so when the user returns to Route
8, this script will continue running (and waiting for 0xD730 to be 0)
Teleport / Fly
● Most maps contain 3 map scripts:
○ CheckFightingMapTrainers
○ DisplayEnemyTrainerTextAndStartBattle
○ EndTrainerBattle
● So after the user teleports to a new map, the new map's current script is
CheckFightingMapTrainers, however the game is affected by a couple things:
○ The START button is disabled, because memory at D730 is not clear and the game thinks the
trainer is still walking towards the user. Until the D730 is clear, most actions are disabled.
○ Going back to Route 8 will have all trainers disabled because Route 8 is in the
DisplayEnemyTrainerTextAndStartBattle script, so no trainer will know to look for you, but only
on that map, other maps will run the CheckFightingMapTrainers script.
The Setup
● After escaping from Route 8, the player will be crippled by the D730, so he
needs to get that cleared. To do that, the player needs to complete a
DisplayEnemyTrainerTextAndStartBattle routine so that the game clears the
value.
The Setup
● By fighting with another trainer that will walk up to you (it has to walk up to
you as otherwise the "walk to user" code won't be called) the game will mostly
go back to a normal state (except Route 8 which is stuck in the battle mode).
The Setup
● When the player is fighting, the game copies several values of the pokemon
and the trainer on to memory, such as the pokemon's type, it's level, hitpoints,
as well as stats such as attack, defense, speed and special.
● CopyData which copies bc bytes (=1+5*2=11 bytes) from hl
(=wEnemyMonLevel) to de (=wEnemyMonUnmodifiedLevel=cd23).
The Setup
● The address in memory where
this data is copied is CD23, and
the amount of data copied is 11
bytes (NUM_STATS is 5,
hitpoints, attack, defense,
speed, special), so up to CD2D.
● Note, however that the memory
in CD2D is also used for
"wEngagedTrainerClass".
The Setup
● This means that wEngagedTrainerClass will be equal to the "special" stat of
the pokemon you fight against. If you fight the youngster, it will be a Slowpoke
with a "special" stat of 21.
The Setup
● Finally, after fighting the youngster, which serves two purposes
○ Marking the memory at D730 to 0, so that the DisplayEnemyTrainerTextAndStartBattle script
doesn't think there's a trainer walking.
○ Setting the memory at CD2D to 21 via the Slowpoke's "special" stat, so that the
wEngagedTrainerClass will hold that value when read the next time.
The Last Step
● The player can now go back to Route 8. Now, when the user enters Route 8,
the game will still try to run the script DisplayEnemyTrainerTextAndStartBattle
but since we already cleared the D730 memory, the game will try to show the
player the enemy text.
The Last Step
● The DisplayEnemyTrainerAndStartBattle script will try to display the text in the
memory pointed by wSpriteIndex, which is the last text shown to the user,
which in our case is usually the START menu. So when the user enters the
map Route 8 the START menu is displayed.
The Last Step
● And after the START menu is dismissed, the script starts the battle, to do so,
it initializes the battle (the pokemon to fight, it's level and so on) with the
function InitBattleEnemyParameters.
The Last Step
● The wCurOpponent (the pokemon type) is set to wEngagedTrainerClass,
which was set to 21 after fighting against the Youngster's Slowpoke
● Since 21 is less than 200, the battle is defined as a "no trainer" (or "wild")
battle, and the pokemon is loaded as 21. 21 is the pokemon identifier for
MEW, so the player fights a "wild" MEW.
The Last Step
How the long range trainer escape glitch (mew trick) works

More Related Content

Similar to How the long range trainer escape glitch (mew trick) works

BB Drac - Unreal Tournament UED2 guide Tutorial DM part 1.pdf
BB Drac - Unreal Tournament UED2 guide Tutorial DM part 1.pdfBB Drac - Unreal Tournament UED2 guide Tutorial DM part 1.pdf
BB Drac - Unreal Tournament UED2 guide Tutorial DM part 1.pdf
TomHodgson19
 
Joker Game.pptx
Joker Game.pptxJoker Game.pptx
Joker Game.pptx
GURU103976
 

Similar to How the long range trainer escape glitch (mew trick) works (16)

Mercurial studios odoricodante_assignment1_0315.pptx
Mercurial studios odoricodante_assignment1_0315.pptxMercurial studios odoricodante_assignment1_0315.pptx
Mercurial studios odoricodante_assignment1_0315.pptx
 
BB Drac - Unreal Tournament UED2 guide Tutorial DM part 1.pdf
BB Drac - Unreal Tournament UED2 guide Tutorial DM part 1.pdfBB Drac - Unreal Tournament UED2 guide Tutorial DM part 1.pdf
BB Drac - Unreal Tournament UED2 guide Tutorial DM part 1.pdf
 
Steam Learn: Speedrun et TAS
Steam Learn: Speedrun et TASSteam Learn: Speedrun et TAS
Steam Learn: Speedrun et TAS
 
prueba02.pdf
prueba02.pdfprueba02.pdf
prueba02.pdf
 
25 tips to build Tutorials on Board Game Arena
25 tips to build Tutorials on Board Game Arena25 tips to build Tutorials on Board Game Arena
25 tips to build Tutorials on Board Game Arena
 
Joker Game.pptx
Joker Game.pptxJoker Game.pptx
Joker Game.pptx
 
Street runner final
Street runner finalStreet runner final
Street runner final
 
Controller trollers odin_1115
Controller trollers odin_1115Controller trollers odin_1115
Controller trollers odin_1115
 
Lecture 3 - Driving.pdf
Lecture 3 - Driving.pdfLecture 3 - Driving.pdf
Lecture 3 - Driving.pdf
 
Uadventure: the eAdventure reboot (How to create educational games)
Uadventure:  the eAdventure reboot (How to create educational games)Uadventure:  the eAdventure reboot (How to create educational games)
Uadventure: the eAdventure reboot (How to create educational games)
 
EDUCON 2017. Digital Education in the Classroom: uAdventure: The eAdventure r...
EDUCON 2017. Digital Education in the Classroom: uAdventure: The eAdventure r...EDUCON 2017. Digital Education in the Classroom: uAdventure: The eAdventure r...
EDUCON 2017. Digital Education in the Classroom: uAdventure: The eAdventure r...
 
Practical level design for F2P
Practical level design for F2PPractical level design for F2P
Practical level design for F2P
 
Usability - One-handed Controller Design
Usability - One-handed Controller DesignUsability - One-handed Controller Design
Usability - One-handed Controller Design
 
Controller Trollers odin_1115
Controller Trollers odin_1115Controller Trollers odin_1115
Controller Trollers odin_1115
 
Video Game Collaboration
Video Game CollaborationVideo Game Collaboration
Video Game Collaboration
 
How to fix steam games not showing up on library
How to fix steam games not showing up on library How to fix steam games not showing up on library
How to fix steam games not showing up on library
 

Recently uploaded

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

How the long range trainer escape glitch (mew trick) works

  • 1. How The Long-Range Trainer Escape Glitch (Mew Trick) Works but like.. technically speaking
  • 2. Agenda ● Background ● Mew Trick Description ● Technical Analysis ○ Glitch ■ CheckFightingMapTrainers vs. UpdateSprites ○ Setup ■ DisplayEnemyTrainerTextAndStartBattle ○ Final Step ■ InitBattleEnemyParameters
  • 3. Background ● It was impossible to get Mew, except by attending Nintendo events, as such it was very exclusive. ● There was a rumour that you could get Mew behind a truck in SS. Anne, but it wasn't true. Many similar rumours turned out to be false as well.
  • 4. Background ● However, one of those rumours turned out to be true! ● And at first, it seemed like yet another scam.
  • 5. Background Apparently first publicly described in March 2003 by Daniel26, but TheScythe made it popular in a forum a month later in in April (and later on analyzed in depth by WhteCat). Daniel26 explained the glitch like this: Ok, first you must not battled the youngster that has a slowpoke (the one past nugget bridge he's the one looking up, about the 4th trainer)and not battled the gambler next to the right entrance to saffron city. THE CODE:fly to saffron city go out the right exit, go up to the door little house (don't go in) press down, quickly press start(before the ! comes onto the gamblers head) fly to cerulan city, go up nugget bridge battle the youngster, walk where he is looking,(when you walk in front of him make sure you have 1 or 2 squares away from him) let him walk to you then he will battle you, after the battle fly to saffron city, try going out the right side exit again, the menu will pop up,press b to get off it then the screen will flash like when a pokemon appears in the grass, and a wild MEW at LV:7 will appear.
  • 6. Pre-requisites ● not battled the youngster that has a slowpoke (the one past nugget bridge he's the one looking up, about the 4th trainer) ● not battled the gambler next to the right entrance to saffron city
  • 7. The Glitch ● go up to the door little house (don't go in) press down, quickly press start
  • 8. The Glitch ● (before the ! comes onto the gamblers head) fly to cerulan city
  • 9. ● fly to cerulan city, go up nugget bridge battle the youngster, walk where he is looking,(when you walk in front of him make sure you have 1 or 2 squares away from him) let him walk to you then he will battle you, The Setup
  • 10. The Last Step ● after the battle fly to saffron city, try going out the right side exit again, the menu will pop up,press b to get off it
  • 11. The Last Step ● then the screen will flash like when a pokemon appears in the grass, and a wild MEW at LV:7 will appear
  • 12. How does that work?
  • 13. Technical Analysis ● The Glitch ○ Escaping from a battle by flying away ● The Setup ○ Fighting with the slowpoke youngster ● The Last Step ○ Going back to where you ran away Sources WhteCat analyzed the glitch and published his notes on "The P Files" github.com/pret has a disassembled version of most Pokemon games
  • 14. Vocabulary ● Trainer ○ An enemy that will fight you if it sees you. ● Sprite ○ Any in-game object, like a trainer, a door, and so on.
  • 15. Technical Background ● GameBoy works the following way: ○ The screen is drawn ○ Code is executed ○ The screen is drawn ○ Code is executed ○ The screen is drawn ○ Code is executed ○ The screen is drawn ○ Code is executed ○ … ● What is drawn on the screen depends on what the code that ran before says
  • 16. Technical Background ● The code (among other things) does: ○ Walking Animation (move the world around the user) ○ Run Map Scripts (code specific to this part of the world) ○ Detect Buttons (if the user pressed any buttons) ○ Check START Menu (if the user pressed the START button) ● The memory (among other things) contains: ○ Temporal memory for holding in-game data. ○ Medium term memory for storing the state in every map. ○ Read only memory for holding the game's code.
  • 17. Map Scripts ● Most maps contain 3 map scripts: ○ CheckFightingMapTrainers ○ DisplayEnemyTrainerTextAndStartBattle ○ EndTrainerBattle ● CheckFightingMapTrainers ○ code responsible for detecting if any trainer can see the player and then having them walk-up to the player ● DisplayEnemyTrainerTextAndStartBattle ○ runs after the previous script, and shows the pre-battle text and starts the battle ● EndTrainerBattle ○ finishes the battle and lets the user continue
  • 18. CheckFightingMapTrainers vs. UpdateSprites ● UpdateSprites: Loop over all Sprites ○ Animate sprites (most move even if static) ○ But don't update sprites if currently walking ● CheckFightingMapTrainers: Loop over all Trainers in the map ○ Ignore those that aren't currently visible ○ If the trainer is looking at the user, fight! This is where the glitch happens!
  • 19. The Glitch ● At first, since the player just moved down, the trainer is not yet visible, and so, can't engage the player. So the player has a single turn to do something before the trainer becomes visible.
  • 20. CheckFightingMapTrainers vs. UpdateSprites ● UpdateSprites: Loop over all Sprites ○ Animate sprites (most move even if static) ○ But don't update sprites if currently walking ● CheckFightingMapTrainers: Loop over all Trainers in the map ○ Ignore those that aren't currently visible ○ If the trainer is looking at the user, fight!
  • 21. CheckFightingMapTrainers vs. UpdateSprites ● The Glitch is simply that there is a "turn" during which the user can do something (move out, or press START) when the Trainer is not yet visible.
  • 22. Teleport / Fly ● When the user Teleports / Flies to somewhere else, the trainer has no time to start the battle, but has enough time to move the script for the current map to DisplayEnemyTrainerTextAndStartBattle
  • 23. DisplayEnemyTrainerTextAndStartBattle ● The Script does the following: ○ Wait for the trainer to finish walking to the player (marked by memory 0xD730) ○ Re-enable the joystick controls (set [wJoyIgnore] = 0) ○ Display the Before Battle Text (marked in wSpriteIndex) ○ Start Battle
  • 24. Teleport / Fly ● When the user Teleports/Flies to another map, the following happens: ○ The current map is left in it's current state ■ This means the "active" script in the current map (route 8) is left as DisplayEnemyTrainerTextAndStartBattle waiting for memory 0xD730 to be 0. ○ The map where you are flying to is set as the new "current" map. ■ The state for each map is stored separately, so this simply leaves the previous state untouched. ● So the Script in the map for Route 8 is left as DisplayEnemyTrainerTextAndStartBattle, so when the user returns to Route 8, this script will continue running (and waiting for 0xD730 to be 0)
  • 25. Teleport / Fly ● Most maps contain 3 map scripts: ○ CheckFightingMapTrainers ○ DisplayEnemyTrainerTextAndStartBattle ○ EndTrainerBattle ● So after the user teleports to a new map, the new map's current script is CheckFightingMapTrainers, however the game is affected by a couple things: ○ The START button is disabled, because memory at D730 is not clear and the game thinks the trainer is still walking towards the user. Until the D730 is clear, most actions are disabled. ○ Going back to Route 8 will have all trainers disabled because Route 8 is in the DisplayEnemyTrainerTextAndStartBattle script, so no trainer will know to look for you, but only on that map, other maps will run the CheckFightingMapTrainers script.
  • 26. The Setup ● After escaping from Route 8, the player will be crippled by the D730, so he needs to get that cleared. To do that, the player needs to complete a DisplayEnemyTrainerTextAndStartBattle routine so that the game clears the value.
  • 27. The Setup ● By fighting with another trainer that will walk up to you (it has to walk up to you as otherwise the "walk to user" code won't be called) the game will mostly go back to a normal state (except Route 8 which is stuck in the battle mode).
  • 28. The Setup ● When the player is fighting, the game copies several values of the pokemon and the trainer on to memory, such as the pokemon's type, it's level, hitpoints, as well as stats such as attack, defense, speed and special. ● CopyData which copies bc bytes (=1+5*2=11 bytes) from hl (=wEnemyMonLevel) to de (=wEnemyMonUnmodifiedLevel=cd23).
  • 29. The Setup ● The address in memory where this data is copied is CD23, and the amount of data copied is 11 bytes (NUM_STATS is 5, hitpoints, attack, defense, speed, special), so up to CD2D. ● Note, however that the memory in CD2D is also used for "wEngagedTrainerClass".
  • 30. The Setup ● This means that wEngagedTrainerClass will be equal to the "special" stat of the pokemon you fight against. If you fight the youngster, it will be a Slowpoke with a "special" stat of 21.
  • 31. The Setup ● Finally, after fighting the youngster, which serves two purposes ○ Marking the memory at D730 to 0, so that the DisplayEnemyTrainerTextAndStartBattle script doesn't think there's a trainer walking. ○ Setting the memory at CD2D to 21 via the Slowpoke's "special" stat, so that the wEngagedTrainerClass will hold that value when read the next time.
  • 32. The Last Step ● The player can now go back to Route 8. Now, when the user enters Route 8, the game will still try to run the script DisplayEnemyTrainerTextAndStartBattle but since we already cleared the D730 memory, the game will try to show the player the enemy text.
  • 33. The Last Step ● The DisplayEnemyTrainerAndStartBattle script will try to display the text in the memory pointed by wSpriteIndex, which is the last text shown to the user, which in our case is usually the START menu. So when the user enters the map Route 8 the START menu is displayed.
  • 34. The Last Step ● And after the START menu is dismissed, the script starts the battle, to do so, it initializes the battle (the pokemon to fight, it's level and so on) with the function InitBattleEnemyParameters.
  • 35. The Last Step ● The wCurOpponent (the pokemon type) is set to wEngagedTrainerClass, which was set to 21 after fighting against the Youngster's Slowpoke
  • 36. ● Since 21 is less than 200, the battle is defined as a "no trainer" (or "wild") battle, and the pokemon is loaded as 21. 21 is the pokemon identifier for MEW, so the player fights a "wild" MEW. The Last Step