Twine Version: Sugarcube 2.5.1
Sorry in advance if the post is confusing: I’m a Javascript newbie, and fairly new to Twine, and there’s still a lot I don’t understand about both.
I want to know how to modify an HTML element to replace it with a Twine passage link using Javascript. Here’s the “user interface” page I’ve set up in Twine, so you have some context for what I want to happen:
When you click a square on the map image, the click event calls a JS function to move you about the map. This function also changes some text on screen to reflect your changed location, by modifying the .innerHTML property of several DIV elements.
I want some of the text on the page – specifically, the text under the header “Patrol Report” – to display text that functions as a regular Twine passage link. However, I have no idea how to go about doing this. I tried copying and pasting the HTML code for a Twine hyperlink into the .innerHTML. This results in a hyperlink that’s styled properly, but when I click on it, it fails to redirect me to my desired passage (hence the orange text).
How do I go about achieving this? It seems like a solution would have something to do with the Wikifier function, but after trawling through the documentation and a few forum posts, I’m still confused I’m not sure how to use that.
An abbreviated version of the function is below. I’m not including the full code, because it’s long.
> function MoveMapLoc(MapLocation) {
>
> /*BLOCK 4 - Update Patrol Line*/
> let PatrolLine = document.getElementById("PatrolLine");
>
> /* Check the value of the MapLocation variable*/
> if (MapLocation == "Railyard") {
> PatrolLine.innerHTML = "<a data-passage='Quest Interface' class='link-internal macro-link' role='link' tabindex='0'>Bells ring, people yell, and smoke rises. I watch a group of men hoisting crates of anonymous goods into the empty belly of a car. I walk towards them...</a>";}