0 votes
by (160 points)
I want to make a global timer, which resets at every new passage so if you don't swich passage after an specific amount of time, you will come back to the first passage. I don't want to have a large code in every passage, so a story javascript would be awesome. I am very bad at coding and didn't manage to make such a code. Can someone please help me?

2 Answers

+3 votes
by (2.2k points)
selected by
 
Best answer

If I understood correctly, this can be implemented by creating passage with special name PassageReady and putting following code there:

<<timed 10s>>
  <<goto [[Start]]>>
<</timed>>

Replace 10s and Start bits with specific amount of time (s is for seconds) and name of your starting passage respectively.

by (159k points)

... putting following code there:

I suggest passing the name of the Passage as a String to the <<goto>> macro instead of passing a Markup based Link, because although it ends up producing the same result the parser has to work harder to extract the Passage name from the Link. eg.

<<timed 10s>>
  <<goto "Start">>
<</timed>>

@Jannybanny123
Individuals reading you story will do so at different rates, this can be due to a number of reasons: from their age; to their need for glasses; to how distracted they are; etc..

So if you really need to implement such a feature please remember those that read slower than others, because it can be real annoying not being able to finish reading something.  

by (2.2k points)

parser has to work harder to extract the Passage name from the Link

Even if difference is 2 orders of magnitude, I doubt that one link will seriously affect game performance, unless it's inside of loop or something. 
Using [[Start]] produces arrows between passages in twine2 editor, that's why I prefer it.

0 votes
by (2.7k points)
In addition to the answer of NotKostas and your wish to avoid extra code in every passage:

simply put his code into a passage with name 'PassageHeader'

then every passage in that story will return to the same passage if not switched.

No further linking or so is needed. No further text in PassageHeader is needed.
by (160 points)
edited by
The code works, but the 'PassageHeader' thing doesn't. I managed to do it without the timer. Thanks for your effort.
by (2.2k points)
IIRC PassageReady doesn't produce screen output, while PassageHeader does. That's why I recommended to use PassageReady here.
by (2.7k points)
Sorry, I completely overlooked the hint/link to PassageReady in your answer.

Sorry for my spam.
by (2.7k points)
Sorry, I completely overlooked the hint/link to PassageReady in the original answer.

Sorry for my spam.
...