Auto-translated
I think you just need to wait for the battle to end, and then run the function again based on the result.
And yes, RedHeaven is right, you need to carefully check the contents. Otherwise, one trigger might overwrite another, at the very least.