It looks like you're new here. If you want to get involved, click one of these buttons!
$('.inlinechoice').on('click','.question', function(e) {
var $this = $(this),
$id = $this.prop('id'),
$class = '.' + $('.answer-' + $id).prop('class').replace('hide', '');
$('.answerblock').hide();
$('.answer-' + $id).show();
$('div[class*=answer]').not($class).hide();
});
Codepen version here: http://codepen.io/anon/pen/HkCgGtry {
version.extensions['fakechoice'] = { major:1, minor:0, revision:0 };
macros['fakechoice'] = {
handler: function(place, macroName, params, parser) {
[...]
};
} catch(e) {
throwError(place,"recall fakechoice Error: "+e.message);
}
But with the javascript sitting in the [...] somehow. Also, I'm not sure if I need more than one macro, i.e. one to set up the inlinechoice, and another to set up the answerblock.//requires jquery
//requires Modernizr
but when I share the javascript from codepen, I can see it makes reference to both libraries.
Comments
For future reference, I found out how to do this here. Basically, to call custom javascript, you need to save the script as a .js file in the same folder as your Twine game, then add this macro as a script passage. Then, when you want to call your javascript in Twine, you just type into a passage: In my case I also went into the 'Story>Special Passages>StorySettings menu and set both jQuery and Modernizr to on.
Apologies if this is repeating common knowledge, but I couldn't find this in the wiki/forum or googlegroups, nor was it obvious anywhere else.
It'd still be nice to change this to a proper twine macro, as ultimately I'm not convinced my javascript is any less clumsy than the combination of using Leon's revision macros for the task but it's doing what I want it to, so that's pretty cool.
Yeah, some of that is news to me. Good post!
Modernizr is used almost exclusively for HTML5 and CSS3 cross-browser compatibility. It's not required in this case, let me assure you.
I've added the script to a script passage (brown header) and called it fakechoice.
Then I've added <<display fakechoice>> and an arrow joins the game passage to the script passage. But it doesn't seem to work (basically I can't click the text and get the response).
https://dl.dropboxusercontent.com/u/11379019/Twine/scripttest.tws
I guess I'm doing something wrong?
Edit: Made more tweaks to the code now, which will pick up clicked choices in order. Working codepen here.