0 votes
by (2.9k points)
Hi, I was wondering if anyone knew about a way to get link history (i.e. previous link the player visited.). The only way I could do it is by creating variables for every link but that takes hours to complete when you have large amounts of links.

If there is a way either in javascript or in sugarcube please share the information.

2 Answers

0 votes
by (68.4k points)

It's unclear whether you want the name of the previous passage or the text of the link that took you there.

Assuming for the moment that it's the former, there are a few ways to get the name of the previous passage.  For example, the previous() function:

The previous passage was <<= previous()>>.

 

by (2.9k points)
Thanks this works but I was wondering if there was a way to set the player to back to the previous passage in the storymenu passage.

 

(Edit, I looked through the web and found the answer, thanks anyways.)
0 votes
by (157k points)

WARNING: My knowledge of Javascript is limited, you may want to get the advice of a more experienced Javascript writer/coder. 

If you are asking how to track which links (in your story) the Reader clicked on to arrive at the current passage being show then you could do something like the following.

1. Initialise a story variable to store the link text of each link selected by the Reader.
This should be done in your story's StoryInit special passage, and the variable is initialised to an empty Array.

<<set $linkHistory to []>>

2. Create a postrender Task Object to handle the tracking of each link selection.
The following code should be placed within your story's Story Javascript area, it creates a postrender task named Link Tracking which appends an extra click event to each of the links within the current passage being shown.

postrender["Link Tracking"] = function (content, taskName) {
	$(content).find("a.link-internal").click(function() {
		State.variables["linkHistory"].push($(this).text());
	});
};

... the above appends the link text of the selected link to the Array stored within the $linkHistory story variable.
note: The above only tracks the links within the passage itself, it does not track links within the StoryMenu or StoryCaption areas.

by (68.4k points)

It's a good answer if it is what the OP wants—as noted in my answer, I was unsure.

That said.  As currently written, that will only affect links which create anchor elements (<a>).  A more comprehensive solution would drop the anchor element selector from the call to $(…).find(), leaving just the class selector.  I'd also suggest adding a namespace, but that's less important.

For example:

postrender['link-tracker'] = function (content) {
	$(content).find('.link-internal')
		.on('click.link-tracker', function () {
			State.variables['linkHistory'].push($(this).text());
		});
};

 

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.
...