Hi ya'll, I seem to have some problems understanding how the trainer flags work in Emerald. I have this script that does some stuff, then enters a trainer battle. On future occasions, it's then supposed to use the checktrainerflag to jump in the script once the battle has already been defeated. However, even after the trainer has been defeated, the script still plays out like normal when talking to the NPC again:
Could someone help me understand what I'm missing? Thanks!
Code:
#dynamic 0x9C0B20
#freespace 0xFF
#org @start
lock
faceplayer
checktrainerflag 0x140
compare LASTRESULT 0x1
if 0x1 goto @alreadyDefeated
msgbox @msg1 0x2
setvar 0x8004 0x0
goto @Loop
#org @Loop
special2 0x8000 0x149
compare 0x8000 0x118
if 0x1 goto @HaveWurmple
addvar 0x8004 0x1
compare 0x8004 0x6
if 0x5 goto @Loop
release
end
#org @HaveWurmple
applymovement 0x5 @move
waitmovement 0x0
sound 0x15
pause 0x30
msgbox @WurmpleIsCute 0x2
trainerbattle 0x0 0x140 0x0 @battleIntro @battleWin
release
end
#org @alreadyDefeated
msgbox @after 0x6
release
end
#org @msg1
= My favorite Pokémon is Wurmple!\nIt's sooooo cute! I really want\lone for myself, but my daddy won't\lbuy me any more Poké Balls...
#org @WurmpleIsCute
= Oh, you have one? Yay!
#org @battleIntro
= Maybe you can show it to me in a\nbattle!
#org @battleWin
= Oh no, you beat me!
#org @after
= My friend says that Wurmple is\ncreepy, but I disagree!
#org @move
#raw 0x56
#raw 0xFE
Could someone help me understand what I'm missing? Thanks!