The value of intention in Halacha is complex. Sometimes, halacha says that intent to perform a mitzvah is part of the essence of the Mitzvah itself. No intention=Meaningless act. Do it over, with a bracha, and intention.
Sometimes, having the intent is an addition praise-worthy component. If you had some good. If you didn’t, don’t worry about it; it’s all good and better luck next time.
Intention is better than no intention. One maamar Chazal (rabbinic expression) has it that if one intended to perform a mitzvah but was impeded by forces truly outside of his control, it counts as an actual deed.
Based on that teaching, the late Chassidic Rebbe Reb Elimelech of Lizensk advised people to intend to perform the Mitzvah of sacrificing one’s life for God. The fact that the scenario does not present itself is neither here nor there. Because your intent mattered.
At first, this might sound like some silly loophole-shtick. But the way the brainwaves move matter. Constant flexing of one’s Intention muscles enhances mental strength.