Remembering a value after restart?
Posted: Thu Jul 21, 2005 7:10 am
I have an intro menu, a short animation, and a title screen that appear before my game begins. If the player restarts the game (there are three ways -- the "restart" command, "restart" from the top menu, and "restart" from a custom menu available during the game) I don't want to show the intro. I just want to start with my introductory text and then begin the first turn.
I have been able to get this partially working, but I just can't figure out how to make it reliable. I have found two ways to remember values after a reload:
1) Save a value to a data file before restarting. This can be checked after the restart, to know that a restart was done, and then re-written with 0.
2) Add a local to remember the global in the DoRestart -- only works there, though.
#1 was partially working, but with two problems. One is, I can only create the file if the user types "restart" or selects to restart from my custom menu. The Hugo menu at the top, which provides an option to restart, doesn't appear to call DoRestart or anything in which I could create my "flag" file first. Also, I have introductory text with a pause. If the game window is closed at that point, the flag file still contains the global, which will be seen and perceived as a restart the next time the game is started. I won't go into detail on why I wasn't deleting the file at the top of main(), but basically it's become of some additional code I would need to skip in my DoMenu() routine (which continues executing *after* the restart) if there was a restart. Regardless, it won't work if the user restarts from the menu at the top. That's why #2 isn't quite the answer, either.
So, I was trying to create a flag file at the beginning of the game, to indicate that the game was running. I thought I could create a random value when the game begins, to know that the "current session" is running. Then, even if the user restarts from the menu, the file would already be there. I could check that value after a restart. The problem there is, if the user quits, what happens to that file? The next time the game starts, it looks like a restart. I thought I could create a random value *only* when the game starts (but not when it restarts), but I'm finding no way.
So.... is there anything in Hugo that won't be reset when the game restarts? Something that I could somehow use to know -- in the init() routine -- that the game just restarted versus starting for the first time this session? I keep thinking there must be *some* way to do it with a temp data file and a random number, but it's eluding me. Even though the drop file can indicate that the game was "already running", it has no context when the game is started or restarted, because I can't tell the difference...
I have been able to get this partially working, but I just can't figure out how to make it reliable. I have found two ways to remember values after a reload:
1) Save a value to a data file before restarting. This can be checked after the restart, to know that a restart was done, and then re-written with 0.
2) Add a local to remember the global in the DoRestart -- only works there, though.
#1 was partially working, but with two problems. One is, I can only create the file if the user types "restart" or selects to restart from my custom menu. The Hugo menu at the top, which provides an option to restart, doesn't appear to call DoRestart or anything in which I could create my "flag" file first. Also, I have introductory text with a pause. If the game window is closed at that point, the flag file still contains the global, which will be seen and perceived as a restart the next time the game is started. I won't go into detail on why I wasn't deleting the file at the top of main(), but basically it's become of some additional code I would need to skip in my DoMenu() routine (which continues executing *after* the restart) if there was a restart. Regardless, it won't work if the user restarts from the menu at the top. That's why #2 isn't quite the answer, either.
So, I was trying to create a flag file at the beginning of the game, to indicate that the game was running. I thought I could create a random value when the game begins, to know that the "current session" is running. Then, even if the user restarts from the menu, the file would already be there. I could check that value after a restart. The problem there is, if the user quits, what happens to that file? The next time the game starts, it looks like a restart. I thought I could create a random value *only* when the game starts (but not when it restarts), but I'm finding no way.
So.... is there anything in Hugo that won't be reset when the game restarts? Something that I could somehow use to know -- in the init() routine -- that the game just restarted versus starting for the first time this session? I keep thinking there must be *some* way to do it with a temp data file and a random number, but it's eluding me. Even though the drop file can indicate that the game was "already running", it has no context when the game is started or restarted, because I can't tell the difference...