I’d like to change the tooltips associated witht the “backward” and “forward” buttons which are at the top of the left-hand GUI column from
Go backward within the game history
Go forward within the game history
to
Go backward within the story history
Go forward within the story history
I.e. to replace “game” by “story”.
What’s the best way to do that?
A little background:
Inspect in Firefox seems to show that the buttons are defined as
<button id="history-backward" tabindex="0" title="Go backward within the game history" aria-label="Go backward within the game history" type="button" role="button"></button>
and
<button id="history-forward" tabindex="-1" title="Go forward within the game history" aria-label="Go forward within the game history" disabled="" aria-disabled="true" data-last-tabindex="0" type="button"
role="button"></button>
The results of some Web searches seemed to claim that a button’s title is what’s shown as the tooltip and I deduced that I could use these Javascript statements to change those titles:
document.getElementById('history-backward').title ='Go backward within the Story history';
document.getElementById('history-forward').title = 'Go forward within the Story history';
Unfortunately, the various techniques that I’ve tried for invoking those statements have either resulted in error messages or in no changes in the tooltips.
SugarCube includes a number of special variables, like setup and l10nStrings that can be used in any of the Private Scoped JavaScript execution contexts created by the SugarCube engine, like those created for:
the Story > JavaScript area of a Twine 2.x application project.
macros like <<script>> and <<run>>.
any Passage that has been assigned the special script Passage Tag.
any js file that is included in the source code path of a Twee Notation compiler, like TweeGo.
So if your project is Twee Notation based, then you can use code that references the special l10nStrings variable to alter the default text that the SugarCube User Interface displays.
(the following has been tested in a new SugarCube project)
l10nStrings.uiBarBackward = "Go backward within the story history";
l10nStrings.uiBarForward = "Go forward within the story history";
edit: It has been pointed out by TheMadExile, that the current v2.37.0 alpha testing release requires an addition property to be set, so the above should be the following for that release…
l10nStrings.textIdentity = 'story';
l10nStrings.uiBarBackward = "Go backward within the story history";
l10nStrings.uiBarForward = "Go forward within the story history";
note: There is no need to wrap the above l10nStrings variable assignments within a JavaScript Immediately Invoked Function Expression.
eg. there is no need to syntax like this…
!function () {
l10nStrings.uiBarBackward = "Go backward within the story history";
l10nStrings.uiBarForward = "Go forward within the story history";
}();
…or this…
(function () {
l10nStrings.uiBarBackward = "Go backward within the story history";
l10nStrings.uiBarForward = "Go forward within the story history";
})();
When I put them in a passage which has the tag [script], for example, the tooltips aren’t changed, although no error messages are generated.
I also tried this:
:: PassageHeader [nobr]
<<script>>
l10nStrings.uiBarBackward = "Go backward within the story history";
l10nStrings.uiBarForward = "Go forward within the story history";
<</script>>
Again, no change.
(I had found that the method I’m currently using, a macro which uses the generic html code to change the button’s title, kept getting undone when I did a browser window refresh. Always calling it before a passage gets rendered fixed that.)
In case it makes a difference, as mentioned back at the start, I’m using the latest SugarCube alpha:
SugarCube 2.37.0-alpha.19+10193
which works quite well for me.
If you’re using the current alpha, place the following into your story JavaScript:
l10nStrings.textIdentity = 'story';
With that you change the identity of the project in all localized references from game to story.
Unless otherwise specified when someone says story JavaScript, JavaScript section, JavaScript sheet, JavaScript anything in relation to Twine we almost always mean:
In Twine 2: the story JavaScript, there’s only one.
In Twee (generally): a script-tagged passage.
In Tweego (specifically): a script-tagged passage or a loose JavaScript file (.js) within your sources.