Revision of Twine macro: << timedreplace >>, << replacewith >>, << endtimedreplace >> from Thu, 03/07/2013 - 05:16

Similar to my <<replace>> macro, this code causes the passage text in between the <<timedreplace>> and <<replacewith>> tags to be replaced with what is between those and the <<endtimedreplace>> tag, after a certain number of halves of seconds have elapsed.

Copy the code in here: http://www.glorioustrainwrecks.com/files/TwineMacro-TimedReplace.txt

By default the text instantly changes with no transition. You can add a fade-in transition with this CSS (or make your own transition!):

.replacement-in {
	opacity: 0;
}
.timedreplacement {
	transition: 1s;
	-webkit-transition: 1s;
}
.replacement-out {
	display:none;
}
Special feature: the <<replacewith>> tag can be omitted! If that is the case, then everything between <<timedreplace>> and <<endtimedreplace>> tags appears when the time elapses.

Mod: if you don't want the replaced passage to fade in, simply delete the line beginning with "fade" near the end (but only that line).

Usage examples:
*<<timedreplace 4 >>You see nothing. <<replacewith>>After 2 seconds, you still see nothing.<<endtimedreplace>>
*You search. <<timedreplace 2>>You find nothing.<<endtimedreplace>>.

Example program.

Implementation details:

* 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. This means that if you put long-term variable changes that affect future passages inside one, you should disable the Back button.
* The passages are two <span>s, one visible, one hidden, each with the "timedreplacement" class. The one that is removed also has the class "timedreplacement1" and the passage that is added has the class "timedreplacement2".

AttachmentSize
TwineMacro-TimedReplaceTest.html37.82 KB
TwineMacro-TimedReplace-1.1.0.txt2.06 KB
pensive-mosquitoes