Remembering a value after restart?

This is a discussion / support forum for the Hugo programming language by Kent Tessman. Hugo is a powerful programming language for making text games / interactive fiction with multimedia support.

Hugo download links: https://www.generalcoffee.com/hugo
Roody Yogurt's Hugo Blog: https://notdeadhugo.blogspot.com
The Hugor interpreter by RealNC: http://ifwiki.org/index.php/Hugor

Moderators: Ice Cream Jonsey, joltcountry

Merk
Posts: 192
Joined: Mon Nov 22, 2004 3:19 pm
Location: Wichita, KS
Contact:

Remembering a value after restart?

Post by Merk »

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

Roody_Yogurt
Posts: 2180
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Post by Roody_Yogurt »

Found this post while searching this base for information on context menus.

Basically, this is the same thing we came across with the comments-in-betatesting thread- the answer being to store something in the word array when DoRestart is run and check for that in init.

This post brings up a good point, though, about how restarting from the interpreter menu skips all of that. Maybe the interpreter menu should force an in-game >RESTART just like the menu SAVE and LOAD already do? It's a thought, anyway.

Bainespal
Posts: 151
Joined: Fri Jul 09, 2010 8:59 am

Post by Bainespal »

Roody_Yogurt wrote:Basically, this is the same thing we came across with the comments-in-betatesting thread- the answer being to store something in the word array when DoRestart is run and check for that in init.
That's quite a crafty solution. I'm glad I don't have to deal with any technical issues this complicated for my purposes.

Post Reply