Hi @SWIFTGI and welcome to the forum!
I don’t think there’s an official way to do this, but it has been discussed in the forum before (here).
I haven’t tested recently, but I created an example extension to demonstrate the concept of storing a value to the micro:bit’s flash memory. It continues to hold a value across a reset or battery change, but not across reprogramming. You can add this extension to projects by: 1) Click on “+ Extensions”, 2) Paste the URL in the search box and press enter/return, and 3) Select the file for the extension. The URL is: https://github.com/bsiever/microbit-pxt-flashstorage .
Here’s an example project that uses it: https://makecode.microbit.org/_hiXaDp0aoAuF (again, I haven’t tested it recently):
- It’ll retrieve a stored counter when it starts.
- Button A increases the counter (but doesn’t update flash)
- Button A+B decreases the counters (but doesn’t update flash)
- Button B will update the flash with the current counter.