{{{<<return>>}}} macro example. Observe the page URL hash.\n\n<<return>>
code,pre { font-size: 1.5em; }\n\nbody { background-color: #fff;\ncolor: #000; }\n\ntable,tr,td { border-width: 1px; border-style: solid; }
!!A note about macro parameters\n\nSome macros take their parameters more seriously than others. Most, such as {{{<<display>>}}}, take their parameters as given - static strings. {{{<<set>>}}} and {{{<<print>>}}}, however, allow you to include variables and operators in them. To differentiate between the two treatments, I'll call the former "literal parameters" and the latter "code parameters".\n\n!! List of macros\n\n{{{<<choice "Passage Name" "Link Text">>}}}\nJonah: creates a link that is otherwise indistinguishable, but becomes disabled when you click it. Disabled links are <span> tags with the "disabled" class that contain identical link text. The "Link Text" parameter is optional. \nSugarcane: creates a normal link.\n\n{{{<<back "parameter" "steps">>}}}\nSugarcane only.\nIf zero parameters are present, then it creates a link to the previous passage visited, removing the current passage ID from the page URL hash (thus functioning similar to the browser's Back button).\nIf one parameter is present, creates a link that goes to whatever passage is specified by "parameter", but only if that passage has already been visited, and by removing all intervening passage IDs from the page URL hash.\nIf the second optional parameter is the word "steps" in lowercase, then "parameter" will be interpreted as a number, and the link will go that many passages backward, removing that many IDs from the page URL hash.\nThe link text is "<b>«</b> Back".\n[[Example.|Back]]\n\n{{{<<return "parameter" "steps">>}}}\nIdentical to {{{<<back>>}}}, except that it does not remove passage IDs from the page URL hash, thus instead functioning as an ordinary link.\nThe link text is "<b>«</b> Return".\n[[Example.|Return]]\n\n{{{<<refresh>>}}}\nSugarcane only. Reloads the page. If this macro is run during the loading of a passage, then the previous passage will be reloaded instead. Otherwise, a "refresh loop" may occur, unceremoniously locking up the game. The utility of this puzzling macro is questionable.\n[[Example.|Refresh]]\n\n{{{<<display "Passage Name">>}}}\nImports the entire contents of a different passage into this passage at this point. Can be useful for including commonly used text, or commonly used macros. If a "display loop" occurs, in which two or more passages try to display each other, an error message will be printed.\n\n{{{<<actions "Passage Name" "Passage Name 2" ... >>}}}\nTakes an unlimited number of parameters. Creates a <ul> element with a series of <li> elements, each containing one of the given parameters as an internal link. Passages that have already been visited as part of an {{{<<actions>>}}} macro are not included. Visited links are internally recorded in a JavaScript object and are //not// saved when you reload the page or use the Back or Forward buttons. Due to a bug, the macro will also be reset if you use the {{{<<back>>}}} or {{{<<return>>}}} macros. <<actions "Example 1" "Example 2" "Example 3">>\n{{{<<print ...>>}}}\nDisplays whatever its parameter evaluates to. Everything between the word "print" and the closing ">>" is treated as a single code parameter.\n\nCode parameters are first preprocessed with TiddlyWiki macro operators/sigils converted to JavaScript operators/prefixes thus:\n| eq | {{{==}}} |\n| neq | != |\n| gt | > |\n| gte | >= |\n| lt | < |\n| lte | <= |\n| and | && |\n| or | {{{||}}} |\n| not | {{{!}}} |\n| $ | state.history[0].variables. |\nThen, the converted parameter is executed as raw JavaScript using eval(), and the resulting value[[*|Bug]] is converted to a string and then printed. This means that, barring the above conversions, you can evaluate and execute as much arbitrary JavaScript inside your game as you like.\n\nOne reason these operators exist is that the greater-than sign '>' is not permitted to appear in a valid macro. Ohter possible reasons may be that "{{{==}}}" is already used for specifying strikethrough text, and furthermore may be easy to confuse with "=" despite having an entirely different purpose. Nevertheless, apart from gt and gte, you can use any of the other JavaScript equivalents instead of the standard operators if you so wish - although it may get a bit confusing if you mix the two.\n\n{{{<<set ... >>}}}\nEvaluates its code parameter, as above. Note that, despite its name, this macro does not actually require the parameter to involve setting a variable to another value.\n\n{{{<<if ... >> ... <<else>> ... <<endif>>}}}\nEvaluates its code parameter, as above. If it evaluates to "true" (that is, a value that isn't false, 0, or an error value) then the code and text between the {{{<<if>>}}} and {{{<<else>>/<<endif>>}}} macros is displayed/executed. Otherwise, if the optional {{{<<else>>}}} macro lies before the {{{<<endif>>}}} macro, then the code and text between them will be displayed/executed instead. If no matching {{{<<endif>>}}} macro can be found, an error message is printed.\n\n{{{<<remember ... >>}}}\nIdentical to {{{<<set>>}}}, but after evaluating, it finds the first state.history[0].variables variable used in the evaluated parameter, and saves its value in a browser cookie. If it can't find such a variable, an error is printed. The cookie value is loaded to the same variable at game start.\nIn version 1.3.5 or below, this doesn't work unless the HTML file is run from a web server. In later versions, this problem is solved by using HTML5 local storage in place of cookies.\n\n{{{<<silently>> ... <<endsilently>>}}}\nExecutes all of the macros between it and the matching {{{<<endsilently>>}}} macro, without displaying any of the text or any of the macros' output.\n\n{{{<<textinput "Variable Name" "Passage Name" "Button Name">>}}}\nCreates an <input type="text"> element. If the optional "Button Name" parameter is present, an <input type="button"> element with the button name is also created. When you press enter inside the textbox or click the button, the state.history[0].variables variable with the name "Variable Name" is set to the raw string contents of the textbox, and you go to the passage "Passage Name".\n\nThe variable name is not a code parameter - it is read as a raw string, although it is inserted into raw JavaScript (the onkeypress action of the text box and the onclick action of the button) almost verbatim. You can write the variable name with the variable sigil (eg. $variablename) or without (eg. "variablename").\n\n<<textinput $variable "textinput" "Example">>\n\n{{{<<update "passage">>}}}\nIf a page element with an ID of "story" followed by the given parameter (eg. "Title" -> "storyTitle") then the contents of that div is replaced with the executed and printed contents of the passage with the title "Story" followed by the given parameter (eg. "Title" -> "StoryTitle). Its only intended purpose is to modify the StoryTitle, StorySubtitle, StoryAuthor and StoryMenu elements by re-executing the code in their passages, but it could also be used for other purposes.\n\nIf no parameter is given, then the StoryTitle, StorySubtitle, StoryAuthor and StoryMenu elements are all updated.\n\n[[Example.|Update]]\n
<<display "Start">>
{{{<<back>>}}} macro example. Observe the page URL hash. If the page is reloaded (by using the browser's Back and Forward buttons, or by opening a bookmark) then the code in this passage will be forgotten.\n\n<<back>>
Refresh example:\n\n<<refresh>>\n\n<<back>>
<<update>>\n\nAs you can see, the StoryAuthor element updated.\n\n<<back>>
Bug in Twine 1.3.5: If you use the browser's Back button or click "Back" or "Return" instead of "A normal link", the actions list will be reset.\n\n[[A normal link|Start2]]\n<<back>>\n<<return>>
Bug in Twine 1.3.5: If you use the browser's Back button or click "Back" or "Return" instead of "A normal link", the actions list will be reset.\n\n[[A normal link|Start2]]\n<<back>>\n<<return>>
Twine 1.3.5 Built-In Macros
Bug in Twine 1.3.5: If you use the browser's Back button or click "Back" or "Return" instead of "A normal link", the actions list will be reset.\n\n[[A normal link|Start2]]\n<<back>>\n<<return>>
setTimeout(function(){ var next = "Start2";\n\nvar h = state.history; if (h[0].passage.title=="Start") { var n = insertElement(null, 'div');n.style.display="none";n.appendChild($("passages").removeChild($("passageStart")));state.display(next,null);$("passages").appendChild(n);}},1);
<<if $updated gt 0>>\n<html><marquee>NEWS FLASH: FLOW OF TIME TO BE SWITCHED OFF AT NIGHT TO SAVE ELECTRICITY</marquee></html>\n<<endif>>\n<<set $updated = 1>>
A well-known bug in Twine 1.3.5 is that the result will not be printed if it evaluates to "false" - which is to say, if the result is the number 0, the boolean value "false", the error value "NaN" (most commonly returned by dividing by 0, running Math.sqrt() on a negative, or being unable to convert a string to a number) and some other stuff. This is fixed in subsequent versions.\n\n<<return>>
You entered "<<print $variable>>".\n\n<<back>>