Twine macro: << timedreplace >>, << timedinsert >>, << timedremove >>, << timedcontinue >>

Similar to my <<replace>> macro, this code causes the passage text in between the <<timedreplace>> and <<becomes>> tags to be replaced with what is between those and the <<endtimedreplace>> tag, after a certain amount of time has elapsed.

Variants
* <<timedinsert>> causes its text to be inserted into the page. It doesn't need a <<becomes>> tag to function.
* <<timedremove>> works in a matching fashion, removing its contained text after the time elapses.
* <<timedcontinue>> is similar to <<timedinsert>> but does not require a final <<endtimedcontinue>> - instead, it causes all subsequent text in the passage to appear.
Gains
You can also substitute the <<becomes>> tag with <<gains>> to cause the next run of text to appear at the end of the previous run, without replacing it.
Chains
If you put multiple <<becomes>> or <<gains>> tags in, the macro will make them appear as well after the same amount of time passes.

Install my <<Replace>> Macro Set to use these macros.

This takes CSS time values, which are decimal numbers ending in "s" (for seconds) or "ms" (for milliseconds).

Usage examples:
* <<timedreplace 2s >>You see nothing. <<becomes>>After 2 seconds, you still see nothing.<<endtimedreplace>>
* <<timedreplace 2s >>You see <<gains>>a dog, <<gains>>a walrus, <<gains>>and a civet.<<endtimedreplace>>
* You search. <<timedinsert 1s>>You find nothing.<<endtimedinsert>>.
* <<timedremove 2.5s >>Something is disappearing... <<endtimedremove>>
* Look <<timedcontinue 3s>>A bird just few by...

Example program.

Implementation details:

* If inserted text appears and descends below the bottom of the screen, the page should automatically scroll down to make it visible.
* Note: due to the way the browser and Twine interact, any changes made by code inside a <<timedreplace>> tag will be forgotten if you use the Back or Forward browser buttons, unless you use this script.

Version history:
* 16/06/2013 - Updated regarding Combined Replace Macro Set.
* 26/04/2013 - Added timedcontinue.
* 05/04/2013 - Added timedinsert and timedremove, as well as downward scrolling.
* 07/03/2013 - Made the transition CSS-based.
* 01/02/2013 - Initial.
Feel free to report any bugs to @webbedspace.

AttachmentSize
TwineMacro-TimedReplaceTest.html37.82 KB
TwineMacros-TimedReplace-2.3.0.txt3.97 KB

Comments

Smedis2's picture

TWINE TUTORIALS

TWINE TUTORIALS EVERYWHEREEEEEEEEEEEE

How do you actually install

How do you actually install the REPLACE Macro??
Like, how would you add this code into Twine 1.4 or Twine 2?

Can't get timedinsert to work

Hi, I hope I'm not the noob who annoys everyone and that someone with proper knowledge of this subject is still active after all this time.

I am working on a story in Twine using the Sugarcane 2.21.0 format.

I have pasted the entire content of the http://twine1.neocities.org/ReplaceMacros.min.js (version 1.1.7) into the "Edit Story Javascript" within Twine. I hope I was right to do so, but believe I am since a test with <<*mousereplace>> which is part of this macro works fine.

Now this is the code I have put in a passage. As you can see I have tried different variations to get this working, but all give an error, which I will put below this code chunk.

<*span class="slowfade"><<*timedinsert 3s>>wait for it<<*becomes>>You should see this text after three seconds, before that the passage should be empty.<<*becomes>>done<<*endtimedinsert>><*/span>

<<*timedinsert 3s>>wait for it<<*becomes>>You should see this text after three seconds, before that the passage should be empty.<<*becomes>>done<<*endtimedinsert>>

<<*timedinsert 3s>>wait for it... done<<*endtimedinsert>>

<<*timedreplace 2s>>You see nothing. <<*becomes>>After 2 seconds, you still see nothing.<<*endtimedreplace>>

<<*timedcontinue 3s>>another timed test<<*endtimedcontinue>>

------
The error message: Error: cannot execute macro <<*timedinsert>>: Cannot read property 'title' of undefined

Which makes me doubt that the text pasted in the js part is correct, but if it wasn't, how is it possible that the <<*mousereplace>> bit works?

Please help, and if I have failed to provide you with enough context, let me know.

Thanks in advance!

ps. I have added * to this message, because in the preview, the tags got masked.. They're not in the actual code

b

SpindleyQ's picture

Hi b, one thing that's

Hi b, one thing that's probably not clear from this page - the macros L posted here were written for Twine 1 and aren't compatible with Twine 2. I think "Edit Story Javascript" is a Twine 2 thing?