Letting the player choose to disable ui-bar history

If you are requesting technical assistance with Twine, please specify:
Twine Version: 2.3.9
Story Format: 2.31.1

OK wizards of intfiction.org…Is there a way to make a button within the starting passage passage that executes this:

Config.history.controls = false;

So the player can choose to disable the ui-bar history. Like for a Hardcore Mode?

Unfortunately, Config.history.controls doesn’t do anything after the game has already started, so you’ll need to use something like this instead:

<<button "Toggle History Controls">>
	<<run $("#ui-bar-history").toggle()>>
<</button>>

That uses the jQuery .toggle() method to toggle the visibility of the history controls, so clicking that button a second time would make the controls visible again.

However, that won’t permanently keep that hidden by itself, since if you load a saved game then the controls will be back. Thus you’ll also need to keep track if that’s supposed to be hidden, and then re-hide it if necessary when a save is loaded. So, the above code changes to:

<<button "Toggle History Controls">>
	<<run $("#ui-bar-history").toggle()>>
	<<set $showHistory = $("#ui-bar-history").css("display") != "none">>
<</button>>

and then you’d need to add this to your JavaScript section:

Config.saves.onLoad = function (save) {
	if (!save.state.history[save.state.index].variables.showHistory) {
		$("#ui-bar-history").css("display", "none");
	}
};

That will re-hide the history controls upon loading a save if $showHistory is set to any “truthy” value.

Enjoy! :slight_smile:

EDIT: Added the parts starting at “However…”.

1 Like

Thanks again, HiEv! I’ll try this and come back to confirm it worked (though I’m pretty sure it will!) :grinning:

tested and it works like a charm. You really are a wizard!

Actually, upon further testing, I find that when loading ANY save, regardless of whether or not the history was previously disabled, the game is loading with history buttons disabled. This is easily fixed by simply refreshing the browser, but can you think of why this might be happening? I think if I implement this as-is, I’m going to get a lot of confused bug reports.

Any thoughts?

Ah, yeah, sorry. Had to reverse the logic so that the default case works properly. Use this:

<<button "Toggle History Controls">>
	<<run $("#ui-bar-history").toggle()>>
	<<set $hideHistory = $("#ui-bar-history").css("display") == "none">>
<</button>>

and this:

Config.saves.onLoad = function (save) {
	if (save.state.history[save.state.index].variables.hideHistory) {
		$("#ui-bar-history").css("display", "none");
	}
};

instead and that should fix that problem. :slight_smile:

P.S. Note that, after toggling this on, you’ll have to go to the next passage before saving for this to work, because the save system doesn’t normally save any changes which happen in the current passage.

1 Like

Understood. I don’t expect that anyone will try to save on the start page…but you never know what weird shit players will do. :upside_down_face: I will test this out and come back here to confirm.

Seems to be working exactly as intended! I even put a Toggle Hardcore Mode button on the sidebar so if people chicken out, they can go back to normal mode. Thanks again!