Skip to content

Instantly share code, notes, and snippets.

View ChapelR's full-sized avatar

Chapel ChapelR

View GitHub Profile
@ChapelR
ChapelR / harlowe-to-sugarcube.md
Last active April 11, 2021 14:10
Harlowe to SugarCube basics

Differences From Harlowe

There are many differences between Harlowe and SugarCube, this section will document some of the most critical you will need to account for if you're coming in to SugarCube from a background in Harlowe.

Macros

Aside from general syntax, SugarCube macros don't use hooks, separate arguments differently, and don't allow other macros to be passed as arguments into macros.

Container Macros

Where Harlowe uses hook syntax (brackets) to associate a macro with its contents, SugarCube instead uses 'container' macros; macros that can have content associated with them have opening and closing tags.

@ChapelR
ChapelR / weightedPassages.js
Created May 29, 2019 12:18
Weighted Passages
(function () {
'use strict';
var passageWeights = {};
function weightedEither (test) {
var passages;
if (test) {
passages = [].slice.call(arguments);
} else {
@ChapelR
ChapelR / README.md
Created May 20, 2019 05:21
Preserve Scroll Position in SC

Usage

Add the tag preserve-scroll to a passage.

@ChapelR
ChapelR / README.md
Created May 20, 2019 02:31
A `<<css>>` macro for SugarCube.

Macro: <<css>>

Syntax

<<css selector propert value [property] [value] [etc...]>>

Arguments

  • selector: the CSS/jQuery selector to an element on the page.
  • porperty value pairs: pairs of CSS properties and the values you wish to set each to. Any number of pairs may be passed to the macro.
@ChapelR
ChapelR / README.md
Last active May 14, 2019 08:50
Layered Background Tags for SugarCube

Add new tags to the system using tagImages().

Function: tagImages()

Assigns a tag to represent an image. Use with fg: and bg: tags (see below) to form layered background images from tags.

Syntax: tagImage(tagName, URL)

  • tagName: the name of the tag to assign the image to.
  • URL: the URL path to the image.
@ChapelR
ChapelR / articles
Last active November 24, 2020 08:49
macros-demo
The articles macro set allows you to prepend words or phrases with the appropriate idenfitine article ("a" or "an").
<<A 'European man'>>.
It's been <<a 'honor'>>.
You can use this macro set for when you need to determine the correct article to use when generating, for example, random loot.
<<set _mats to either('iron', 'wooden', 'steel', 'adamantium', 'crystal')>>\
@@#output;You found <<a _mats>> sword!@@
@ChapelR
ChapelR / swap.js
Last active January 11, 2019 21:51
swap macro set
/*
the following `(function () {...}());` statement creates a local scope for our JavaScript code.
this is called an IIFE, or "immediately invoked function expression". most langauges have block scoping,
JS has function scoping. think of this as a way to get block scoping to prevent any of our stuff from
polluting the global scope.
*/
(function () {
/*
@ChapelR
ChapelR / harlowe-transfer.js
Created December 28, 2018 09:14
Harlowe: Transfer Data Between Episodes
(function () {
// transfer Harlowe data between stories via local storage
var _state = State; // scope hack the state
var storageKey = '%%twine-game-episode-transfer'; // change this to something with your story's title in it
var hasStorage = (function () {
return !!window.localStorage;
}());
\<<widget 'tenth'>>
\ <span id="typewriter"></span>
\ <<set _textArrayLength to 0, _i to 0, _output to ''>>
\ <<repeat .1s>>
\ <<if _textArrayLength gte $args[_i].length>>
\ <<set _i++, _textArrayLength to 0>>
\ <<if _i gte $args.length>>
\ <<stop>>
\ <</if>>
\ <<set _output to _output + '<br />'>>