Hi, I'm using Twine 1.4 - Sugarcube (more specifically Responsive)
I've tried using things from
http://twinery.org/forum/discussion/2918/binding-a-key-to-a-link/p1 but it comes up with an error
It says "There is a technical problem with this story (keybinding: $(...).ready is not a function)"
I'm using Chrome, for some reason Microsoft Edge (what I'd been using to debug before since at one point Chrome wouldn't run tests, only uploaded versions) but currently Edge doesn't work when I turn off the ability for people to rewind the story, it tries to restart the story whenever you click a link.
Also I have to have rewind off, because I'm revisiting certain pages quite a few times, so can't have the super long url. It causes an error after a while, plus I don't want people to re-wind things.
I've also changed the text given in the above link to:
$(document).ready(function () {
$(document).on("keypress", function (event) {
if (event.which == 38) {
$("#storySubtitle")
.find('a[data-passage="Up"]')
.trigger("click");
}
});
});
Comments
If you're using Responsive, as you claim, then it sounds like you haven't enabled jQuery (jQuery is not included with the Twine 1 vanilla story formats by default). You may do so via the StorySettings special passage (Story menu > Special Passages > StorySettings).
Ok, I enabled JQuery, but I could only do so by disabling Modernizer, is that supposed to happen? Otherwise it does the "noDefaultCSS" break.
Though thanks the error is not when I run the story now, but the keybindings still don't work.
You have several additional issues you need to resolve. A possible issue with your link and two code issues, an issue with the event you're listening for and another issue with how the vanilla story formats register events.
Possible Link Issue
Unlike SugarCube, the vanilla story formats do not generate normalized links for all link types. Unless you're using HTML markup to create your link, it probably doesn't have a "data-passage" attribute, so your secondary selector won't match. The solution is to only use HTML markup for the links you want to trigger via JavaScript. For example:
Code Issue: Event
You can't use "keypress" to identify all keys—in particular, the arrow keys will thwart you. So, for the arrow keys, change the event you're listening for to "keydown".
Code Issue: Event Registration
Even with the above two issues resolved, triggering a click on the link via jQuery won't work due to the way the vanilla story formats register click events.
To resolve the final two issues, you could change your code to something like the following: (I dropped the superfluous ready() wrapper) That won't work in ancient browsers (e.g. IE≤8), but I don't really consider that an issue—YMMV.
with
And it's saying Script Error when I press a key. Do you think my use of Sugarcane instead of SugarCube could be the problem?
As for SugarCube vs. the vanilla story formats. Using the vanilla formats hasn't been helping you here, no, but that's not the cause of your latest issue.
In what passage are you putting your link? I'd assumed, based on the selector you provided in the opening post, that you were putting it in the StorySubtitle special passage. I'm asking, because I'm guessing the error you received was because querySelector() isn't finding the link, which makes the chained call to dispatchEvent() fail. That's just a guess though, "Script Error" isn't much to go on.
The exact thing is
"Sorry to interrupt, but this story's code has got itself in a mess. (Script error) ou (sic.) may be able to continue playing, but some parts will not work properly. "
I'm putting it in an ordinary passage called Directions, I was modifying some code I found previously, yet I don't know entirely about the code.
Thanks for saying that thing is a special passage, I removed that part of the code and now it works, hurrah!
Thanks for your help