It's only working because you can't do that, and it runs anyways (Atleast not in PKSV's new version. Just do checkflag, if true.)
What you should do is:
if 0x1 goto @finished
Also, logically you're setting the trainerflag if you haven't battled (which is wrong). Here's a PKSV representation of what it should look like.
= Do you want to battle?
= Next time then.
= That was a good battle!
= Prepare for battle!
= Damn I lost
Try that PKSV version, you can convert it to XSE easily, if you wish.
Umm FBI, trainer flags work backwards. They are cleared when you beat them. Another name for settrainerflag is enabletrainer. They are interchangeable names for the same command. Same goes for cleartrainerflag, its other optional name is disabletrainer.
I know that the commands themselves work that way, but the settrainerflag 0x0 command may be equivalent to a standard clearflag 0x500 (trainer flags are just regular flags starting at 500 if I remember correctly) so there is a chance that the main names for the commands are misleading. The only way to really tell would be to take a clean rom and right off the bat, checkflag 0x500 and see what it holds.
Proof- I wrote a working script to make every trainer in the game ready to battle again. It didn't work when I logically used cleartrainerflag, so when I switched to setrainerflag, everybody wanted to battle again.
Edit: Comrade likes your Signiture.