HP Forums

Full Version: Preserving highscores from accidental opening of program code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a way to make a program save a number into an external variable or memory without it being erased everytime the user opens the program code? This is problematic because all other calculator models use ENTER to execute programs, while the HP Prime uses F6, so if I have a game where the highscore is saved, then the player will usually press ENTER by reflex to launch the game, only to have not only the code opened instead but also his highscore erased.

I was also thinking of working on a role-playing game with saving options, but have been reluctant about starting such project at all because of the save data being erased over and over.
You can save the highscores in a Home variable, out of the program, with HVars.
(03-01-2023 11:01 PM)Kevin Ouellet Wrote: [ -> ]Is there a way to make a program save a number into an external variable or memory without it being erased everytime the user opens the program code? This is problematic because all other calculator models use ENTER to execute programs, while the HP Prime uses F6, so if I have a game where the highscore is saved, then the player will usually press ENTER by reflex to launch the game, only to have not only the code opened instead but also his highscore erased.

I was also thinking of working on a role-playing game with saving options, but have been reluctant about starting such project at all because of the save data being erased over and over.

I believe in the new project structure you can have side variables and data that is kept on the side and not part of the source. Nor is it compiled. Basically, a place for data and binary info to reside without appearing in user editable areas normally.
Heya, sorry I am very late! I actually took a while to figure out how to use HVar and I first gave up until recently when I picked up my game again and now I figured it out. Thanks for letting me know about HVar. I have now checked the on-calc help but I prefered downloading the PDF copy to my computer so it's easier to read on the larger screen. HVar seems to work with other type of variables too, which I am happy about.
Why don't you want to use the resources assigned to a specific program as TW mentioned? Of course, HVars will work correctly, but then the data saved in this way are shared in HOME for different programs, and if another program uses the same name, it will overwrite them.
On the other hand, resources (e.g., 'binary asset') are a very interesting solution when you want to have isolated files for a specific program in the 'Program Catalog' without the need to create an app. It's perfect for graphics (so you don't have to use ICON), but also for binary data. For me, it's an ideal solution to save the current game state or the highscores. I'm currently updating my game 'Radioactive Wastes' to utilize this mechanism.
I prefer avoiding using apps. I had way too many problems running custom apps in the past and I prefer to use a more functional alternative that is hpprgm.
What I'm referring to is indeed hpprgm. This feature was introduced quite recently (in one of the latest firmware versions). It's a regular program (not an app) in the 'Program Catalog' that has the ability to nest other files within itself, which are not reset when someone opens the source code. Take a look at the on-calc help for the "Resource" command. If you need more details, I can prepare a usage example for you.
Oh I see now. I didn't know about this feature. I'll check the help later!
I think you should read this thread:
Program "project" structure - how to use?

I've described a bit more about this topic here, mainly what to watch out for.
Reference URL's