Git Product home page Git Product logo

twine-cookbook's People

Contributors

chapelr avatar cyrusfirheir avatar evelynmitchell avatar greyelf avatar jamesskemp avatar klembot avatar mcdemarco avatar mscherer avatar na-sa-do avatar tmedwards avatar videlais avatar webbedspace avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twine-cookbook's Issues

Lock and key

A piece of text (e.g. a link to open a door) only appears if the player has previously visited another passage (e.g. where they found the right key).

Using images

Image support and functionality is pretty mixed across story formats, but there should still be examples on the two most commonly used ways of including images in Twine 2 stories: Base64-encoding and referencing a file.

Headers and Footers

Examples of how to create headers and footers using passage tags (Harlowe), special passage names (SugarCube), and templated window.story.render() usage (Snowman) .

Turn counter

The text of a passage changes depending on the number of passages the player has visited. e.g. at the start of a game, it's morning; later on, it becomes afternoon and the description of a place changes.

Expanded Twee page

Given the Twee 3 specification, expand the Twee page in the Cookbook. Include information about Twee Notation and compilers. Optionally include more details about the versions of Twee and their general differences.

Delayed text

Two similar ideas:

  • Text that only appears after viewing a passage for a certain amount of time.
  • Simulating a 'typewriter' effect on a passage.

Hidden links

A link that only reveals itself to be clickable when the reader mouses over it, or doesn't change at all.

Using Add-ons in SugarCube

An entry on loading and potentially using one of the add-ons supplied by @tmedwards in the SugarCube documentation downloads page. It would also list the ability to use the existing add-ons as other possible solutions to the entries on Cycling Links and the Typewriter Effect topic areas already in the Cookbook.

This would be a topic area with a single entry for SugarCube.

Harlowe cycling example in the cookbook

I'm new to all this and the cookbook and Harlowe manual have both proved absolute lifesavers. However, I've noticed that the Harlowe code example for cycling choices used in the cookbook doesn't appear to work when typed into twine 2, even when it's just copy-pasted.
It involves a lot of "if $choicecount>=it then set to 1" and it just seems a little overwhelming as a beginner.
I couldn't spot any proposed alternatives, so I took the liberty of providing my own that seemed a little less clunky (at least from here, I'll happily admit that I'm learning a lot of this as I go)

Isn't it easier to just rotate the array and always display the first entry? If you update the button every second then you can just keep on clicking. You can even add a back button by copying the code and changing it to rotate -1

EXAMPLE
(set: $choicecount to (a: ["One"], ["Two"], ["Three"]))
(live:1s)[(display: 1st of $choice)]
[Next]<next|
(live:1s)[(click: ?next)[(set: $choicecount to (rotated:1,...$choicecount))]

Setting up a simple "go" button has proven a little difficult, but I've had some success using a secondary passage that loads up the choices. as its basically only functioning as a directory that the reader doesn't see

EXAMPLE 2
CHOICE PASSAGE
(set: $choicecount to (a: ["One"], ["Two"], ["Three"]))
(live:1s)[(display: 1st of $choice)]
[Next]<next| [Go]<go|
(live:1s)[(click: ?next)[(set: $choicecount to (rotated:1,...$choicecount))]
(live:1s)[(click: ?go)[(go-to: "Loader Passage")]

LOADER PASSAGE
(if: 1st of $choicecount = ["One"] [(go-to: "Passage One")]
(if: 1st of $choicecount = ["Two"] [(go-to: "Passage Two")]
(if: 1st of $choicecount = ["Three"] [(go-to: "Passage Three")]

There's probably an easier solution somewhere, but if this is any help for the cookbook, please take it. If I'm just creating more issues than I've solved I'm sorry for wasting time but I'd appreciate any criticism so I can get better at this.

Arrays heading in ToC

I just realized that the examples and recipes I wrote for arrays are in the repo here, but when I committed them I forgot to add them to the table of contents so they're inaccessible in the built page. I can submit PR later if you don't get to it.

Dice rolling

How to simulate the outcome of a die roll -- either the standard d6 or the more esoteric variations.

"Moving through a 'dungeon'" example

Commentary on the SugarCube example

The markdown document for the SugarCube "Moving through a 'dungeon'" example has the wrong filename: sugarcube_displayswapping.md.

Please, do not use <<end…>> style closing tags (I'm looking at you <<endif>>). They have been deprecated for a very long time now and are no longer even mentioned in the documentation.

Using conditional and command statements

Like #22, this may seem basic, but the structure of conditional and command statements is different enough across story formats that it is worth including examples of things like Harlowe's (else-if:) and SuagrCube's <<switch>> that either aren't available or are different in the other story formats.

Date and Time Examples

Getting the current date, time, and doing basic time manipulation. Assume using Date() for SugarCube and Snowman examples where functionality is not already supplied by story format or included libraries.

SugarCube disabling saving with an alert.

Greyelf suggested I post this here.

Not really an issue in Harlowe, since authors will typically have different save and load buttons, so they can just use (if:)s to get whatever effect they want. In SugarCube, using Config.saves.isAllowed() to deactivate saving causes the save to just fail silently, which could cause users to lose data if they assume it worked, or think there's a bug or something. The following code is based on something TheMadExile wrote up for me a long time ago, and shows an alert when saving is disabled and the user attempts it:

Config.saves.isAllowed = function () {
    if (tags().includesAny('no-save', 'menu', 'creation', 'startup') /* etc... */ ) {
        $(document).one(':dialogclose', function () {
            // show alert when save dialog is closed by the save attempt
            UI.alert("You can't save right now.");
        });
        return false;
    }
    return true;
};

Cycling text that's remembered

The player can click a cycling link whose final value is remembered later in the game (e.g. choosing a hair color for the protagonist).

Type writer effect in SugarCube.

I just wanted to point out that SugarCube has an integration module for Typed.js on its website (under add-ons, dead last), that will probably be a better solution than the widget for most authors. I can see the value in providing code that authors can make and understand themselves, but I think it'd be wise to at least mention its existence.

Saving Games -> SugarCube ->Save.slots.ok() vs Save.ok()

See: sugarcube_savinggames_twee.txt, line: 19

<<link "Save to the first slot?">>
	<<script>>
		if (Save.ok()) { 
			Save.slots.save(0);
		}
	<</script>>
<</link>>

The above test should use Save.slots.ok(), as Save.ok() will return true if either slots or the autosave is available. You don't want the autosave check masking an issue with the slots.

Minor Typo in Sugarcube Hidden Links

As the title states, there's a typo in the section for having a link reveal itself permanently upon mouseover.
It reads
$('.reveals') .addClass('hidden') .one('mouseenter', function () { $(this).removeClass('hidden'); });

It should be .on instead of .one

Functionality encapsulation using display, include, and render()

This technique is already present in many of the Version 1 examples, but it is not spelled out as such in most case. This set of examples would (optionally) define the term encapsulation and demonstrate how to use the (display:), <<include>>, and render() functionality of Harlowe, SugarCube, and Snowman respectively to separate complex ideas into easier-to-handle modules.

CSS Section

Break out the CSS page into its own section with details on the differences between what selector each included story format uses (<tw-story> for Harlowe, .passage, and .main for Snowman) for their content area and how to style links and other common selector issues.

This section should include or otherwise summarize the upcoming Twine 2 HTML Elements specification.

"Quicktime event" style reverse progress bar (SugarCube 2 only)

For inclusion in the cookbook, if deemed of good enough quality. The <<quicktimebar>> macro creates a simple "reverse progress" bar which starts out filled (and in a nice green shade), then becomes smaller with time and acquires an angry red tint until the time runs out, at which point whichever code is nested inside is ran, like a <<link>>'s code would. If navigating away from the passage, nothing executes.

Example code (a 5-second timer, 20em wide, showing an alert popup when nothing happens to stop it):

<<quicktimebar 5 20em>><<run UI.alert("Too late!")>><</quicktimebar>>

CSS:

div.quicktime-bar {
	position: relative;
	border: 1px solid #777;
	background: black;
	height: 1em;
}

div.quicktime-value {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	background: #00ff00;
}

JavaScript:

Macro.add("quicktimebar", {
	isAsync : true,
	tags: null,
	handler: function() {
		var payload = this.payload[0].contents.replace(/\n$/, '').trim();
		var duration = (Number(this.args[0]) || 60) * 1000;
		var width = this.args[1] || "100%";
		var id = "bar_" + Math.floor(Math.random() * 0x100000000).toString(16);
		
		var bar = document.createElement("div");
		bar.classList.add("quicktime-bar");
		bar.id = id;
		bar.style.width = width;
		var value = document.createElement("div");
		value.classList.add("quicktime-value");
		value.style.width = "100%";
		bar.appendChild(value);
		
		this.output.appendChild(bar);
		
		var toHex = function(num) {
			var res = Math.round(Number(num)).toString(16);
			return (res.length === 1 ? "0" + res : res);
		};
		var functionToRun = this.createShadowWrapper(
			payload
				? function() { Wikifier.wikifyEval(payload); }
				: null
		);
		
		jQuery(document).one(":passagedisplay", function() {
			var timeStarted = (new Date()).getTime();
			var workFunction = setInterval(function() {
				if(!bar.isConnected) {
					// Navigated away from the passage
					clearInterval(workFunction);
					return;
				}
				var timePassed = (new Date()).getTime() - timeStarted;
				if(timePassed >= duration) {
					// Timed out - run the inner SugarCube code
					value.style.width = "0";
					clearInterval(workFunction);
					setTimeout(functionToRun, 40);
					return;
				}
				// Update the quicktime bar
				var percentage = 100 - 100 * timePassed / duration;
				var color = "#"
					+ toHex(Math.min(255, 510 -  5.1 * percentage))
					+ toHex(Math.min(255, 5.1 * percentage)) + "00";
				value.style.backgroundColor = color;
				value.style.width = (100 - 100 * timePassed / duration) + "%";
			}, 40);
		});
	},
});

Most of the styling can be done with CSS. The colour change happens near the end of the workFunction function and can be changed there or commented out - or overridden via an !important CSS rule.

Attribution: Whatever, I'm glad to help.

Iteration

Examples of how to use (loop:) (Harlowe), <<for>> (SugarCube), and for() (Snowman) to iterate over different data structures and how to show, find, and sort things.

Version 3: SugarCane Support

Examples in SugarCane of the following to matching existing sets:

  • Setting and Showing Variables
  • Conditional Statements
  • Modularity

Adjusting Player Statistics

Examples of how to assign and use multiple values across story formats. Based on, and drawing heavily from, examples like those found in SugarCube's documentation.

Examples could be as simple as a handful of numerical values and how to adjust them using (link:)/<<link>> or as complex as including some random events (connecting to the Rolling Dice example) for how to build very simplified RPG mechanics of events/battle outcomes affecting values.

Static "health" bars (using <progressbar>, <meter>, and CSS)

Examples demonstrating multiple approaches (if possible in story format) for showing static data using <progressbar>, <meter>, and other CSS methods.

(This topic area should be different than the Timed Progress Bars entries that already exist. These should be about showing static and not dynamic data changes.)

Detect disabled JS and still show table of contents?

As per suggestion, see if GitBook's HTML rendered content will still show the table of contents without the search functionality. Both use JavaScript (and the examples themselves would not work without it), but it might still be possible.

An alternative might also be to have the published PDF and EPUB versions on the site as well.

Style markup / markdown

Examples demonstrating most if not all of the style markup in the given story format.

References:
Harlowe, SugarCube under "Basic Formatting," and how to achieve the same effects in Snowman using CSS and HTML elements.

Setting and showing variables

Just as the title says, this would be a review of how to "set" and show variables across story formats. While this is usually one of the first things learned when using a story format, it also differs across them enough that a review of how to set, change, and show values is worth including.

Possible Suggestions:

  • (set:) in Harlowe, <<set>> in SugarCube, and "s" scope in Snowman
  • Reviewing the keyword "it" in Harlowe
  • Unary operations in SugarCube and Snowman (e.g. negation and increment)
  • Using print and text macros

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.