Redirect to another passage

Hi,

I been trying to set a countdown that will auto lead to an other passage after an amount of time. I found out that code who is working great. But I can’t find the way to set the destination to an other passage. As you can see I put google home site to test the thing…

It’s in Harlowe

30

Might help to let people know which IF authoring program/tool you’re trying to do this with. I’m new to the site but that seems to not be apparent. :wink:
EDIT: Yay, so it’s Harlowe. That’d be Twine. Can’t help you there but I’m sure now someone will be able to. I think it’s weird the system let you post directly to Authoring without any sub-category to begin with. Maybe that’s a bug, or maybe it’s a feature, I dunno.

1 Like

I can’t see any code in you post, so I’m not sure which part is or isn’t working great.

Regardless, the following should do what you want:

{
(set: $time to 0)
(set: $timelimit to 30)

(live: 1s)[
     (set: $time to ($time + 1))
     (if: $time > $timelimit)[
          (stop:)
          (goto:"Passage Name")
          ]
     ]
}

This is set up for 30 seconds, but can be edited to whatever amount of time you want.

If you want the timer to persist through multiple passages, put the set variable macros in the startup passage, and the counter in the passages themselves. If you want it to count, but not go anywhere in certain passages, you would just need:

(live: 1s)[
     (set: $time to ($time + 1))
     ]
2 Likes

I though I copie/paste but here is the code I used :

< html>
< body>
< div id=“counter”>30
< script>
setInterval(function() {
var div = document.querySelector("#counter");
var count = div.textContent * 1 - 1;
div.textContent = count;
if (count <= 0) {
window.location.replace(“https://www.google.com”);
}
}, 1000);
< /script>
< /body>
< /html>

I don’t know why but the code wont show ? Well if I put a space after the < it does show but margin are really messed up :s

I can’t speak to the javascript, but if you’re using Harlowe the following should work:

(open-url: "http://www.google.com/")

(goto-url: "http://www.google.com/")

The first opens a new tab, the second replaces the current tab.

note: I will assume you were trying to use this forum’s “Preformatted Text” tool-bar option to include the following example.

<div id="counter">30</div>
<script>
	setInterval(function() {
		var div = document.querySelector("#counter");
		var count = div.textContent * 1 - 1;
		div.textContent = count;
		if (count <= 0) {
			window.location.replace("https://www.google.com");
		}
	}, 1000);
</script>

The Harlowe story format has been deliberately design to restrict an Author’s ability to use JavaScript to access the internals of it’s engine, it also has limited support for using JavaScript in general.

Where exactly in your project did you place your example?

Because if I add the above example to the contents of a Passage and then view it within the story HTML file, I see a countdown which results in a URL redirection when it reaches zero.

1 Like

The countdown actually work, I had issue redirecting to an other passage. But it did work when I put an web URL

redirecting to an other passage

Harlowe’s engine doesn’t include support for “URL based Passage Navigation”, which is why your updating of window.location with a Passage related URL didn’t work. If you want such functionality then you will need to implement it yourself, however the fact that Harlowe doesn’t have a documented JavaScript API makes doing that difficult.

Thank that piece of knowledge is appreciated !