0

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:

  1. Main program creates datachanger.exe and dataholder.txt

  2. Main program launches datachanger.exe

  3. datachanger.exe is constantly checking wether main program process is still alive

  4. Main program closes

  5. datachanger.exe opens the dead main program, deletes last 6 symbols, inserts new ones instead

  6. datachanger.exe launches an independent console script that kills it (suicidal maneuver) and deletes together with dataholder.txt

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

  • You can use QProcess from Qt for launching/killing/getting PIDs and exit codes of your child process. It is crossplatform. However This would require you to link (statically given your self-contained executable policy) to QtCore. – Félix Cantournet Dec 18 '14 at 10:35
  • I will have this library in mind. By the way, I'm also statically linking the SFML library. –  Dec 18 '14 at 10:37
  • What are the obvious downsides of using `system()`? It's maybe the only cross-platform way to run a script. Why not use it? – anatolyg Dec 18 '14 at 10:38
  • "datachanger.exe opens the dead main program" - I'm curious; where will the dead main program be at this stage? On disk? In memory? If it has died, won't it just have been removed from memory? – Component 10 Dec 18 '14 at 10:39
  • 4
    This seems like a really bad idea. The user may not (should not) have permissions to modify an executable. And you're likely to make anti virus software unhappy. Why not just store data in a data file? – Alan Stokes Dec 18 '14 at 10:40
  • @AlanStokes I think that one file would be more user friendly than two. Consider user downloading the game on desktop. That additional cfg file looks awful and just asks to be deleted. –  Dec 18 '14 at 10:51
  • @component10 the dead main program is on disk, closed and no longer in RAM. It has to be not running because you can't edit executables that are running –  Dec 18 '14 at 10:52
  • #anatolyg the downsides are listed in many sites, just search a little. Here's an example on this [link](http://stackoverflow.com/questions/1107705/systempause-why-is-it-wrong) –  Dec 18 '14 at 10:54
  • @MariusMacijauskas: so you're talking about editing the disk image of your executable? I think you will have a *big* challenge to do this in a cross-platform neutral way. I also agree with Alan Stokes that this is likely to cause you more problems than it solves, for the sake of a having a single file rather than two. – Component 10 Dec 18 '14 at 11:00
  • @Component10 Nevertheless, there still should be a way to do it. For the sake of learning and pure elegancy, at least. –  Dec 18 '14 at 11:27
  • 1
    @MariusMacijauskas As a potential user : I don't see how the heck I would be confused by 2 files instead of one. The average games ships with 1 million files. I just don't care. I care about a shortcut on my desktop, with the proper icon. Not that this is easy to do in a crossplatform way... – Félix Cantournet Dec 18 '14 at 15:55

0 Answers0