{"id":1728,"date":"2017-03-23T14:38:25","date_gmt":"2017-03-23T14:38:25","guid":{"rendered":"http:\/\/443.nmdprojects.net\/2017\/?page_id=1728"},"modified":"2017-04-11T03:17:04","modified_gmt":"2017-04-11T03:17:04","slug":"twine-tips","status":"publish","type":"page","link":"http:\/\/443.nmdprojects.net\/2017\/twine-tips\/","title":{"rendered":"Twine Tips"},"content":{"rendered":"<h3>Guides<\/h3>\n<ul>\n<li>\u00a0<a href=\"http:\/\/twinery.org\">Twine<\/a>\u00a0\u00a0&amp;\u00a0<a href=\"http:\/\/twinery.org\/wiki\/twine2:how_to_create_your_first_story\">Twine Guide<\/a><\/li>\n<li><a href=\"http:\/\/www.adamhammond.com\/twineguide\/\">Twine Beginner&#8217;s Guide<\/a><\/li>\n<li><a href=\"http:\/\/www.motoslave.net\/sugarcube\/2\/docs\/macros.html#macrocat-audio\">Sugarcube 2 Macro Library<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3>Models<\/h3>\n<ul>\n<li>\u00a0<a href=\"http:\/\/ifdb.tads.org\">Internet Fiction Database<\/a><\/li>\n<li><a href=\"http:\/\/52twinestories.tumblr.com\">52 Twine Stories<\/a>\u00a0&#8211;a great way to explore many features of Twine via models<\/li>\n<li>\u00a0<a href=\"https:\/\/bravemule.itch.io\/beneathfloes\">Beneath Floes<\/a><\/li>\n<li><a href=\"http:\/\/commondatastorage.googleapis.com\/itchio\/html\/80011\/index.html\">A Cold Grave<\/a><\/li>\n<\/ul>\n<h3>Code<\/h3>\n<p><a href=\"https:\/\/www.glorioustrainwrecks.com\/node\/5019\">Adding or replacing text in a lexia<\/a>: \u00a0put the .js from this URL into your javascript sheet, then use the following text in your passage:<\/p>\n<pre>You have to do something. Either \\\r\n&lt;span id=\"cut\"&gt;\\\r\n &lt;&lt;click \"cut\"&gt;&gt;\\\r\n &lt;&lt;replace \"#cut\"&gt;&gt;cut &lt;&lt;\/replace&gt;&gt;\\\r\n &lt;&lt;replace \"#walkaway\"&gt;&gt;walkaway&lt;&lt;\/replace&gt;&gt;\\\r\n &lt;&lt;replace \"#output\"&gt;&gt;\r\n You have chosen to cut the tree. The wind whips through the white pines and howls.&lt;&lt;\/replace&gt;&gt;\\ \r\n &lt;&lt;\/click&gt;&gt; \\\r\n&lt;\/span&gt;\\\r\nthe tree or \\\r\n&lt;span id=\"walkaway\"&gt;\\\r\n &lt;&lt;click \"walkaway\"&gt;&gt;\\\r\n &lt;&lt;replace \"#cut\"&gt;&gt;cut &lt;&lt;\/replace&gt;&gt;\\\r\n &lt;&lt;replace \"#walkaway\"&gt;&gt;walkaway&lt;&lt;\/replace&gt;&gt;\\\r\n &lt;&lt;replace \"#output\"&gt;&gt;\r\n You have chosen to walkaway. The wind [[whispers]] through the white pine needles like a lover.&lt;&lt;\/replace&gt;&gt;\\ \r\n &lt;&lt;\/click&gt;&gt; \\\r\n&lt;\/span&gt;.\\\r\n\r\n&lt;span id=\"output\"&gt;&lt;\/span&gt;\\<\/pre>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>Variables<\/p>\n<pre>&lt;&lt;set $variable to \"true\"&gt;&gt;\r\n\r\n&lt;&lt;if $variable is \"true\"&gt;&gt;Example Text - true &lt;&lt;elseif $variable is \"false\"&gt;&gt;Example Text - false &lt;&lt;endif&gt;&gt;<\/pre>\n<p>TEXT BOXES<\/p>\n<pre>&lt;&lt;textbox \"$variable\" \"Default Input\" \"Next Passage\"&gt;&gt;\"\r\n\r\n&lt;&lt;print $variable&gt;&gt;<\/pre>\n<hr \/>\n<pre class=\"code\"><a href=\"https:\/\/twinery.org\/wiki\/twine2:add_an_inventory_system\">Adding an inventory system.<\/a>\r\n\r\n\/\/ Begin Inventory Macros\r\n\/\/ Original macros by F2Andy: http:\/\/strugglingwithtwine.blogspot.ca\/2014\/03\/handling-inventory.html\r\n\/\/\r\n\/\/ Instructions:\r\n\/\/\r\n\/\/ 1. In a passage, check if there's an item in the inventory...\r\n\/\/ ...if not, give the user the option to link to a passage that adds it to inventory:\r\n\/\/ &lt;&lt;if $inventory.indexOf(\"An Unsigned Note\") == -1&gt;&gt;There is a note here. [[Pick up the note.]]&lt;&lt;endif&gt;&gt;\r\n\/\/\r\n\/\/ 2. In a passage, check if there's an item in the inventory..\r\n\/\/ ...if so, give the user a choice to progress to a new passage:\r\n\/\/ &lt;&lt;if $inventory.indexOf(\"The Golden Key\") == -1&gt;&gt;[[Unlock the door.]]&lt;&lt;endif&gt;&gt;\r\n\/\/\r\n\/\/ 3. To add an \"Inventory\" link in your sidebar menu, create a passage named \"StoryMenu\".\r\n\/\/ In it, create a link to your inventory's passage: [[Inventory]] or [[Backpack]], for example.\r\n\/\/ Create a passage named \"Inventory\", and in it, write something like the following:\r\n\/\/ &lt;&lt;if $inventory.length == 0&gt;&gt;You are not carrying anything.&lt;&lt;else&gt;&gt;You are carrying:\r\n\/\/ &lt;&lt;invWithLinks&gt;&gt; &lt;&lt;endif&gt;&gt;\r\n\/\/ &lt;&lt;back&gt;&gt;\r\n\r\n\/\/ A helper function for the following macros.\r\nwindow.getInv = function() {\r\n  return state.active.variables.inventory;\r\n}\r\n\r\n\/\/ Starts your inventory. You need to call this once at the start of your game in order to make the inventory work.\r\n\/\/ Usage: Place &lt;&lt;initInv&gt;&gt; in your StoryInit passage. Don't have a StoryInit passage? Make one.\r\nmacros.initInv = {\r\n  handler: function(place, macroName, params, parser) {\r\n    state.active.variables.inventory = [];\r\n  }\r\n};\r\n\r\n\/\/ Add an item to your inventory:\r\n\/\/ Usage: &lt;&lt;addToInv rock&gt;&gt; or &lt;&lt;addToInv \"a smooth rock\"&gt;&gt;\r\nmacros.addToInv = {\r\n  handler: function(place, macroName, params, parser) {\r\n    if (params.length == 0) {\r\n      throwError(place, \"&lt;&lt;\" + macroName + \"&gt;&gt;: no parameters given\");\r\n      return;\r\n    }\r\n    if (state.active.variables.inventory.indexOf(params[0]) == -1) {\r\n      state.active.variables.inventory.push(params[0]);\r\n    }\r\n  }\r\n};\r\n\r\n\/\/ Removes an item from your inventory\r\n\/\/ Usage: &lt;&lt;removeFromInv rock&gt;&gt; or &lt;&lt;removeFromInv \"a smooth rock\"&gt;&gt;\r\nmacros.removeFromInv = {\r\n  handler: function(place, macroName, params, parser) {\r\n    if (params.length == 0) {\r\n      throwError(place, \"&lt;&lt;\" + macroName + \"&gt;&gt;: no parameters given\");\r\n      return;\r\n    }\r\n    var index = state.active.variables.inventory.indexOf(params[0]);\r\n    if (index != -1) {\r\n      state.active.variables.inventory.splice(index, 1);\r\n    }\r\n  }\r\n};\r\n\r\n\/\/ Display the inventory as a list: Rock, Paper, Scissors\r\n\/\/ This can go in any passage, but the best spot would be your [[Inventory]] passage.\r\n\/\/ Usage: &lt;&lt;inv&gt;&gt;\r\nmacros.inv = {\r\n  handler: function(place, macroName, params, parser) {\r\n    if (state.active.variables.inventory.length == 0) {\r\n      new Wikifier(place, 'nothing');\r\n    } else {\r\n      new Wikifier(place, state.active.variables.inventory.join(','));\r\n    }\r\n  }\r\n};\r\n\r\n\/\/ Display the inventory as a series of links to passages with the same names.\r\n\/\/ This can go in any passage, but the best spot would be your [[Inventory]] passage.\r\n\/\/ Usage: &lt;&lt;invWithLinks&gt;&gt;\r\n\/\/ If those passages don't exist, the links will be broken.\r\n\/\/ There is a line break after every item in the inventory.\r\nmacros.invWithLinks = { \r\n  handler: function(place, macroName, params, parser) {\r\n    if (state.active.variables.inventory.length == 0) {\r\n      new Wikifier(place, 'nothing');\r\n    } else {\r\n      new Wikifier(place, '[[' + state.active.variables.inventory.join(']]&lt;br&gt;[[') + ']]');\r\n    }\r\n  }\r\n};\r\n\r\n\/\/ Empty the inventory entirely.\r\n\/\/ Note: This is not like \"dropping\" an object; they are not added to the current room\/passage. It just erases them all entirely.\r\n\/\/ Usage: &lt;&lt;emptyInv&gt;&gt;\r\nmacros.emptyInv = { \r\n  handler: function(place, macroName, params, parser) {\r\n    state.active.variables.inventory = []\r\n  }\r\n};\r\n\/\/ End Inventory Macros<\/pre>\n<hr \/>\n<pre class=\"code\"><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Guides \u00a0Twine\u00a0\u00a0&amp;\u00a0Twine Guide Twine Beginner&#8217;s Guide Sugarcube 2 Macro Library &nbsp; Models \u00a0Internet Fiction Database 52 Twine Stories\u00a0&#8211;a great way to explore many features of Twine via models \u00a0Beneath Floes A Cold Grave Code Adding<a class=\"read-more\" href=\"http:\/\/443.nmdprojects.net\/2017\/twine-tips\/\">More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1728","page","type-page","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/443.nmdprojects.net\/2017\/wp-json\/wp\/v2\/pages\/1728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/443.nmdprojects.net\/2017\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/443.nmdprojects.net\/2017\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/443.nmdprojects.net\/2017\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/443.nmdprojects.net\/2017\/wp-json\/wp\/v2\/comments?post=1728"}],"version-history":[{"count":10,"href":"http:\/\/443.nmdprojects.net\/2017\/wp-json\/wp\/v2\/pages\/1728\/revisions"}],"predecessor-version":[{"id":1846,"href":"http:\/\/443.nmdprojects.net\/2017\/wp-json\/wp\/v2\/pages\/1728\/revisions\/1846"}],"wp:attachment":[{"href":"http:\/\/443.nmdprojects.net\/2017\/wp-json\/wp\/v2\/media?parent=1728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}