HP Forums
Preserving highscores from accidental opening of program code - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Preserving highscores from accidental opening of program code (/thread-19607.html)



Preserving highscores from accidental opening of program code - Kevin Ouellet - 03-01-2023 11:01 PM

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.


RE: Preserving highscores from accidental opening of program code - Didier Lachieze - 03-02-2023 02:43 AM

You can save the highscores in a Home variable, out of the program, with HVars.


RE: Preserving highscores from accidental opening of program code - Tim Wessman - 03-06-2023 05:31 AM

(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.


RE: Preserving highscores from accidental opening of program code - Kevin Ouellet - 10-23-2023 04:26 AM

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.


RE: Preserving highscores from accidental opening of program code - komame - 10-23-2023 01:11 PM

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.


RE: Preserving highscores from accidental opening of program code - Kevin Ouellet - 10-23-2023 07:31 PM

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.


RE: Preserving highscores from accidental opening of program code - komame - 10-23-2023 09:04 PM

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.


RE: Preserving highscores from accidental opening of program code - Kevin Ouellet - 10-23-2023 09:49 PM

Oh I see now. I didn't know about this feature. I'll check the help later!


RE: Preserving highscores from accidental opening of program code - komame - 10-24-2023 07:59 AM

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.