0 votes
by (210 points)
closed by
I'm finishing up a game that makes very careful use of fading in certain images and audio loops at specific times, and I keep running into the following problem: when a player refreshes the page, Sugarcube remembers what page they were on and immediately reloads it (good!). However, it loses track of whatever audio was playing/whatever images had been faded in, and therefore shows a page with no sound and the default CSS (bad!).

I figure there are two possible solutions to this:

1) Get Sugarcube to remember what audio is currently playing, as well as what CSS fades have been implemented with jQuery on previous pages.

2) Force a full game restart (i.e., call Engine.restart()) on a browser refresh. (This isn't a big deal as the game is only ~20 minutes long.)

I'm happy with either of these solutions, but I can't figure out how to implement either. I imagine #2 is easier. Any advice?
closed with the note: Figured out the answer, which I posted here.

2 Answers

0 votes
by (210 points)
selected by
 
Best answer

I've solved this question, so I will be locking it, but I'm leaving my answer here for others. My main goal was to figure out how to disable the default Sugarcube functionality which saves the user's place in the story on a browser refresh. JQuery has a built-in handler for detecting "deloading" a page that fires both when closing the window and when refreshing the page. So all I needed to do was add a handler binding to my story Javascript that restarts the engine before deloading the page:

 

$(window).on('beforeunload', function(){
	Engine.restart();
});

 

0 votes
by (35.5k points)
edited by

Just to be clear, since they give you totally different answers, what do you mean by "when a player refreshes the page"?  Do you mean, "when a player goes to a new passage in the game"?  Or do you mean, "when the player hits the reload button on the browser, F5, or CTRL+F5"?

It kind of sounds like you mean the latter, however, that's not something they should ever need to do (unless, possibly, the game is online and the download of an image failed, or something like that).

by (210 points)
When a player hits the refresh button on the browser! My problem is with the native sugarcube functionality that saves progress on a browser refresh. I would ideally like to disable it, so that refreshing the browser has the same effect as opening a new browser window directed to the same page (i.e., it starts the story over at the beginning).
by (61.3k points)
Keep in mind that doing this will likely break the game on mobile browsers, since they often refresh the page in the background to free up memory. There are other, more direct solutions to fix audio problems from the refresh without potentially breaking mobile support or causing refreshes / browser navigation to reset everything.
by (210 points)
I hadn't known that, thank you for letting me know! Do you have any specific suggestions?
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...