Let's say, I want to create a single-file game with one variable - 6 digit highscore. I think that the process of saving the variable would be something like this:
Main program creates datachanger.exe and dataholder.txt
Main program launches datachanger.exe
datachanger.exe is constantly checking wether main program process is still alive
Main program closes
datachanger.exe opens the dead main program, deletes last 6 symbols, inserts new ones instead
datachanger.exe launches an independent console script that kills it (suicidal maneuver) and deletes together with dataholder.txt
When script is over, it's over. We have main program with a new variable hiding inside.
I see no problem with steps #1, #4, #5 and #7. However, steps #2, #3 and #6 are problematic. I can easily make them run with system(), but we all know the obvious downsides of this choice. CreateProcess() works only on Windows, so does GetExitCodeProcess() for the step #3. I don't know any solution besides system() for step #6, even that works reliably only on Windows.
Do I absolutely have to find out the OS user is using before the variable saving procedure? What's the function for step #6 that works reliably and doesn't require the call of system() on Windows? Maybe it's possible to reduce the amount of steps required or simplify them?
I want to make my little games extremely user friendly.